Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=278 int main() { int N, aux, Vector_1[10005], Vector_2[10005], Elemente = 0; std::cin >> N; aux = N; for (int i=0; i<N; i++) std::cin >> Vector_1[i]; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Vector_2[i]; std::sort(Vector_1, Vector_1 + aux, std::greater <int>()); std::sort(Vector_2, Vector_2 + N, std::greater <int>()); for (int i=0 ;; i++) { if (Vector_1[i] > Vector_2[0]) Elemente++; else break; } std::cout << Elemente; } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=497 int main() { int N, X = 0, Aparitie = 0; long long int Numar[100005], Majoritar; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar[i]; if (X == 0) { X = 1; Majoritar = Numar[i]; } if (X != 0) { if (Majoritar != Numar[i]) X--; else X++; } } for (int i=0; i<N; i++) { if (Numar[i] == Majoritar) Aparitie++; } if (Aparitie > N/2) std::cout << "DA " << Majoritar; else std::cout << "NU"; } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=1883 int main() { int N; long long int Array[1005]; bool Found; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Array[i]; for (int i=0; i<N; i++) { Found = false; for (int j=i; j<N; j++) { if (Array[j] > Array[i]) { Found = true; std::cout << Array[j] << " "; break; } } if (Found == false) std::cout << -1 << " "; } } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=551 int main() { int N, Elevi, Talent = 0; long long int Numar, Max = 0; bool Clasa = false; std::cin >> N >> Elevi; for (int i=0; i<N; i++) { Clasa = false; for (int i=0; i<Elevi; i++) { std::cin >> Numar; if (Numar > Max) { Max = Numar; Talent = 1; Clasa = true; } else { if (Clasa != true and Numar == Max) { Talent++; Clasa = true; } } } } std::cout << Max << " " << Talent; } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=1893 Problema cere să se afișeze un număr de 9 cifre diferit de cele citite de la tastatură. Se poate vedea exemplu din problemă: 4 123456789 987654321 112345567 200000001 orice număr de 9 cifre diferit de numerele de mai sus este declarat ca și un răspuns câștigător. Răspunsul oficial arată în felul următor: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; long a,b,c ; int main() { srand (time(NULL)); a = rand()%21623+10000; b = rand()%21623+10000; c = a*b ; cout << c ; return 0; } Însă eu n-am stat să-mi bat capul cu așa ceva, așa că soluția mea arată în felul următor: int main() { printf("112355372"); } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=383 Solutia autorului problemei: int main(){ int n,k,v[200]; cin >> k >> n; for(int i = 0 ; i < n ; ++ i) cin >> v[i]; for(int i = 0 ; i < n ; ++ i) { int x = v[i] / k * k; int y = x + k; if(v[i] - x <= y - v[i]) v[i] = x; else v[i] = y; } for(int i = n - 1 ; i >= 0 ; -- i) cout << v[i] << " "; return 0; } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=161 int main() { int N, Array[205], Elemente = 0, Suma = 0; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Array[i]; if (Array[i] != 0) Elemente++; Suma += Array[i]; } Suma /= Elemente; for (int i=0; i<N; i++) { if (Array[i] == 0) Array[i] = Suma; std::cout << Array[i] << " "; } } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=496 bool Prim(int Numar_1, int Numar_2) { int Divizori_1[205], Divizori_2[205], size_1, size_2; size_1 = size_2 = 0; for (int i=2; i<=Numar_1; i++) { if (Numar_1 % i == 0) Divizori_1[size_1++] = i; } for (int i=2; i<=Numar_2; i++) { if (Numar_2 % i == 0) Divizori_2[size_2++] = i; } for (int i=0; i<size_1; i++) { for (int j=0; j<size_2; j++) if (Divizori_2[j] == Divizori_1[i]) return false; } return true; } int main() { int N, Array[205], Elemente = 0; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Array[i]; for (int i=0; i<N; i++) { if (Prim(Array[i], Array[N-1])) Elemente++; } std::cout << Elemente; return 0; } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link https://www.pbinfo.ro/?pagina=probleme&id=495 bool Prim(long long int Numar) { if (Numar < 2 or Numar % 2 == 0) return false; if (Numar == 2) return true; for (int i=3; (i*i)<=Numar; i+=2) { if (Numar % i == 0) return false; } return true; } int main() { int N, size = 0; long long int Array[205], Numar; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar; if (Prim(Numar)) Array[size++] = Numar; } for (int i=(size-1); i>=0; i--) std::cout << Array[i] << " "; return 0; } Edited December 19, 2019 by Kelton Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=494 #include <iostream> int main() { int N, Array[205], Vector[205], Suma = 0; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Array[i]; Suma += Array[i]; } for (int i=0; i<N; i++) { Vector[i] = (Suma - Array[i]); std::cout << Vector[i] << " "; } return 0; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=498 #include <iostream> bool CMMDC(int Numar_1, int Numar_2) { int Divizori_1[205], Divizori_2[205], size_1 = 0, size_2 = 0; for (int i=1; i<=Numar_1; i++) { if (Numar_1 % i == 0) Divizori_1[size_1++] = i; } for (int i=1; i<=Numar_2; i++) { if (Numar_2 % i == 0) Divizori_2[size_2++] = i; } for (int i=0; i<size_1; i++) { for (int j=0; j<size_2; j++) { if (Divizori_2[j] != 1 and Divizori_2[j] == Divizori_1[i]) return false; } } return true; } int main() { int N, Array[205], Elemente = 0; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Array[i]; for (int i=0; i<N; i++) { for (int j=i+1; j<N; j++) if (CMMDC(Array[i], Array[j])) Elemente++; } std::cout << Elemente; return 0; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=1860 #include <iostream> #include <fstream> int main() { std::ifstream Read("blackfriday.in"); std::ofstream Write("blackfriday.out"); int N, Index; double Pret_Real[15], Pret_Ieftinire[15], Procent, Max = 0; Read >> N; for (int i=0; i<N; i++) Read >> Pret_Real[i]; for (int i=0; i<N; i++) Read >> Pret_Ieftinire[i]; for (int i=0; i<N; i++) { Procent = (float)100 - ((100 * Pret_Ieftinire[i]) / Pret_Real[i]); if (Procent > Max) { Max = Procent; Index = i+1; } } Write << Index; Read.close(); Write.close(); return 0; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=493 #include <iostream> int sum_cif(long long int Numar) { int Suma = 0; while (Numar != 0) { Suma += Numar % 10; Numar /= 10; } return Suma; } int main() { int N, Suma_Cifre; long long int Array[205], arr[205]; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Array[i]; for (int i=0; i<N; i++) { Suma_Cifre = sum_cif(Array[i]); arr[i] = Array[i] % Suma_Cifre; std::cout << arr[i] << " "; } return 0; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=499 #include <iostream> int main() { int N, Suma = 0, Suma_2 = 0, Elemente = 0; long long int Array[205], aux, aux_2; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Array[i]; for (int i=0; i<N; i++) { aux = Array[i]; while (aux != 0) { Suma += aux % 10; aux /= 10; } for (int j=i+1; j<N; j++) { aux_2 = Array[j]; while (aux_2 != 0) { Suma_2 += aux_2 % 10; aux_2 /= 10; } if (Suma == Suma_2) Elemente++; Suma_2 = 0; } Suma = 0; } std::cout << Elemente; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=2858 #include <iostream> int main() { int N, Suma_1 = 0, Suma_2 = 0, Suma_3 = 0, Divizibile = 0; int Array[205]; std::cin >> N; for (int i=0; i<N; i++) std::cin >> Array[i]; for(int i=N-1, j=1, k=1; i>=0; i--, j++, k++) { std::cout << Array[i] << " "; if (Array[i] % 2 == 0) Suma_1 += Array[i]; if (j % 2 == 0) Suma_2 += Array[j-1]; if (Array[i] % 10 == 0) Divizibile++; if (k % 2 != 0 and Array[k-1] % 3 == 0) Suma_3 += Array[k-1]; } std::cout << "\n" << Suma_1 << "\n" << Suma_2 << "\n" << Divizibile << "\n" << Suma_3; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=986 #include <iostream> int main() { int N, Elemente = 0; double Array[205], a, b; std::cin >> N; for(int i=0; i<N; i++) std::cin >> Array[i]; if (Array[0] > Array[N-1]) { a = Array[N-1]; b = Array[0]; } else { a = Array[0]; b = Array[N-1]; } for(int i=0; i<N; i++) { if (Array[i] >= a && Array[i] <= b) Elemente++; } std::cout << N - Elemente; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=958 #include <iostream> using namespace std; int main() { int n, m, P = 0, nr, putere, prefix, sufix; long long C = 1, cif; cin >> n; m = n; cif = 1; nr = 9; while (n) { if (nr < n) { C += nr * cif; n -= nr; } else { C += n * cif; n = 0; } cif++; nr *= 10; } n = prefix = m; sufix = 0; putere = 1; while(n / 100) { sufix = sufix + (n % 10) * putere; n /= 10; prefix = n / 10; putere *= 10; if (prefix * sufix > P) P = prefix * sufix; } cout << P << ' ' << C; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=487 #include <iostream> int main() { int N, size = 0, Numere = 0; float Array[205], Ma, Numar, Suma = 0; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar; Array[size++] = Numar; Suma += Numar; } Ma = (float)Suma / N; for (int i=0; i<size; i++) { if ((float)Array[i] > (float)Ma) Numere++; } std::cout << Numere; } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Link: https://www.pbinfo.ro/?pagina=probleme&id=490 #include <iostream> int main() { int N, Numar, Index = 1, IndexMax, IndexMin, Max = 0, Min = 39e+69; int Array[1001], size = 0, IndexStart, IndexStop; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar; Array[size++] = Numar; if (Numar > Max) { Max = Numar; IndexMax = Index; } if (Min > Numar) { Min = Numar; IndexMin = Index; } Index++; } Index = 1; if (IndexMax > IndexMin) { IndexStart = IndexMin; IndexStop = IndexMax; } else { IndexStart = IndexMax; IndexStop = IndexMin; } for (int i=0; i<size; i++) { if (Index == IndexStart) { while (Index != (IndexStop+1)) { std::cout << Array[i] << " "; Index++; i++; } } Index++; } } Edited December 18, 2019 by shanker' Link to comment Share on other sites More sharing options...
Andreigl Posted December 18, 2019 Author Share Posted December 18, 2019 Link: https://www.pbinfo.ro/?pagina=probleme&id=1452 #include <iostream> int main() { int Array[1505], N, P; std::cin >> N >> P; for (int i=1; i<=N; i++) std::cin >> Array[i]; for (int i=1; i<=N; i++) { if (i == P) Array[i] = -1; } for (int i=1; i<=N; i++) if (Array[i] != -1) std::cout << Array[i] << " "; } Link to comment Share on other sites More sharing options...
Andreigl Posted December 18, 2019 Author Share Posted December 18, 2019 Link: https://www.pbinfo.ro/?pagina=probleme&id=1453 #include <iostream> int main() { int N; std::cin >> N; long long int Array[N]; for (int i=0; i<N; i++) { std::cin >> Array[i]; if (Array[i] % 2 == 0) Array[i] = -1; if (Array[i] != -1) std::cout << Array[i] << " "; } } Link to comment Share on other sites More sharing options...
Andreigl Posted December 18, 2019 Author Share Posted December 18, 2019 Link: https://www.pbinfo.ro/?pagina=probleme&id=61 #include <stdio.h> long long int euclid(long long int a, long long int b) { long long int c; while (b) { c = a % b; a = b; b = c; } return a; } int main() { long long int a,b; scanf("%lli %lli", &a, &b); for(int i=1; i<=euclid(a,b); i++) if(a % i == 0 and b % i == 0) printf("%d ", i); return 0; } Link: https://www.pbinfo.ro/?pagina=probleme&id=64 #include <stdio.h> int main() { long long int N, Suma = 0; scanf("%lli", &N); for(int i=1; (i*i)<=N; i++) { if (N % i == 0) { Suma += i; if ((i*i) < N) Suma += (N/i); } } if ((N*2) == Suma) printf("%lli este perfect", N); else printf("%lli nu este perfect", N); return 0; } Link to comment Share on other sites More sharing options...
Andreigl Posted January 19, 2020 Author Share Posted January 19, 2020 Link: https://www.pbinfo.ro/probleme/491/suma2 #include <iostream> int main() { int N, Numar, X_Index, Y_Index, Suma = 0; int Array[1001], size = 0, IndexNR = 1; bool ExistaPare = false; std::cin >> N; X_Index = Y_Index = 0; for (int i=0; i<N; i++) { std::cin >> Numar; Array[size++] = Numar; if (Numar % 2 == 0) ExistaPare = true; if (Numar % 2 == 0 and X_Index == 0) X_Index = IndexNR; else if (Numar % 2 == 0 and X_Index != 0) Y_Index = IndexNR; IndexNR++; } if (ExistaPare == false) { std::cout << "NU EXISTA"; return 0; } IndexNR = 1; for (int i=0; i<Numar; i++) { if (IndexNR == X_Index) { while (IndexNR != (Y_Index+1)) { Suma += Array[i]; i++; IndexNR++; } } IndexNR++; if (IndexNR >= Y_Index) break; } std::cout << Suma; } Link to comment Share on other sites More sharing options...
Andreigl Posted January 19, 2020 Author Share Posted January 19, 2020 Link: https://www.pbinfo.ro/probleme/547/numarare6 #include <iostream> int main() { int N, size = 0, Egalitate = 0; long long int Numar, Min = 39e+69, Max = 0, Diferenta, Array[1001]; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar; Array[size++] = Numar; if (Numar > Max) Max = Numar; if (Min > Numar) Min = Numar; } Diferenta = Max - Min; for (int i=0; i<size; i++) { if (Array[i] == Diferenta) Egalitate++; } std::cout << Egalitate; } Link to comment Share on other sites More sharing options...
Andreigl Posted January 19, 2020 Author Share Posted January 19, 2020 (edited) Link: https://www.pbinfo.ro/probleme/488/afisare #include <iostream> int main() { int N, Numar, Index = 1, GreaterSize, LowerSize; int IndexGreater[1001], IndexLower[1001]; GreaterSize = LowerSize = 0; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar; if (Index % 2 == 0) IndexGreater[GreaterSize++] = Numar; if (Index % 2 != 0) IndexLower[LowerSize++] = Numar; Index++; } for (int i=0; i<=(GreaterSize-1); i++) std::cout << IndexGreater[i] << " "; std::cout << std::endl; for (int i=(LowerSize-1); i>=0; i--) std::cout << IndexLower[i] << " "; } Link: https://www.pbinfo.ro/probleme/553/pozminmax #include <iostream> int main() { int N, Index = 1, IndexMax, IndexMin; long long int Numar, Max = 0, Min = 39e+69; std::cin >> N; for (int i=0; i<N; i++) { std::cin >> Numar; if (Numar > Max) { Max = Numar; IndexMax = Index; } if (Min > Numar) { Min = Numar; IndexMin = Index; } Index++; } std::cout << IndexMin << " " << IndexMax; } Edited January 19, 2020 by shanker' Link to comment Share on other sites More sharing options...
Recommended Posts