Last active
January 3, 2024 23:09
-
-
Save robertnitu02/7f25c3a56163fbf1105a3d120db487c1 to your computer and use it in GitHub Desktop.
PBinfo: Probleme Rezolvate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
ifstream in("sum.in"); | |
ofstream out("sum.out"); | |
int main() { | |
int S = 0, a, b; | |
in >> a >> b; | |
S = a + b; | |
out << S; | |
in.close(); | |
out.close(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, S=0; | |
cin >> n; | |
while(n!=0) { | |
S += n%10; | |
n=n/10; | |
} | |
cout << S; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
ifstream in("nrapprime.in"); | |
ofstream out("nrapprime.out"); | |
bool prim(int n) { | |
if(n < 2) return false; | |
if(n == 2) return true; | |
if(n % 2 == 0) return false; | |
for(int d = 3; d * d <= n; d+=2) | |
if(n%d==0) return false; | |
return true; | |
} | |
int main() { | |
int n, v[101], elPrime=0; | |
in >> n; | |
for(int i=1;i<=n;i++) { | |
in >> v[i]; | |
if(prim(v[i])) elPrime++; | |
} | |
out << elPrime; | |
in.close(); | |
out.close(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int a,b,max; | |
cin >> a>> b; | |
max = a; | |
if(b>max) | |
max = b; | |
cout << max << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int a,b,c, min; | |
cin >> a>> b >> c; | |
min = a; | |
if(b<min) | |
min = b; | |
if(c<min) | |
min = c; | |
cout << min << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
if(n % 2 == 0) | |
cout << n << " este par"; | |
else | |
cout << n << " nu este par"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b, diferenta=0; | |
cin >> a >> b; | |
diferenta = a - b; | |
cout << diferenta; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int a,b; | |
int main() | |
{ | |
cin>>a>>b; | |
cout<<a+b<<" "<<a-b<<" "<<a*b<<" "<<a/b; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b, c, suma=0; | |
cin >> a >> b; | |
suma = a+b; | |
c=suma%10; | |
cout << c; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "math.h" | |
using namespace std; | |
int main() { | |
int n, r; | |
cin >> n; | |
r = sqrt(n); | |
cout << r; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b, R; | |
char operatie; | |
cin >> a >> b >> operatie; | |
switch(operatie) { | |
case '+': { | |
R = a + b; | |
cout << R; | |
break; | |
} | |
case '-': { | |
if(a > b) | |
R = a - b; | |
else | |
R = b - a; | |
cout << R; | |
break; | |
} | |
case '*': { | |
R = a * b; | |
cout << R; | |
break; | |
} | |
case '/': { | |
if(a > b) | |
R = a / b; | |
else | |
R = b / a; | |
cout << R; | |
break; | |
} | |
default : cout << "Operatorul nu exista!"; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "math.h" | |
using namespace std; | |
int main() { | |
int n; | |
float R; | |
cin >> n; | |
R = sqrt(n); | |
cout << R; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
#include <fstream> | |
using namespace std; | |
ifstream in("pbinfo.in"); | |
ofstream out("pbinfo.out"); | |
int main() { | |
char sir_link[101], cuvinte[100][103]; | |
in.get(); | |
in.get(sir_link, 101); | |
int n, k = 0; | |
in >> n; | |
while(n) { | |
in.get(); | |
in.get(cuvinte[k], 103); | |
k++; | |
n--; | |
} | |
if(strstr(sir_link, "virus")) | |
out << "DA"; | |
else { | |
bool E = false; | |
for(int i = 0; i < k; i++) { | |
if(strstr(sir_link, cuvinte[i])) { | |
E = true; | |
break; | |
} | |
} | |
if(E) | |
out << "DA"; | |
else | |
out << "NU"; | |
} | |
in.close(); | |
out.close(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
long long n, r; | |
cin >> n; | |
r = (n * (n+1)) / 2; | |
cout << r; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
using namespace std; | |
bool E(char alt[], char carac) { | |
int i = 0; | |
for(i = 0; i < strlen(alt); i++) { | |
if(alt[i] == carac) | |
return false; | |
} | |
return true; | |
} | |
int main() { | |
char sir[256], alt[256]; | |
cin.get(sir, 256); | |
int l = strlen(sir), k = 0; | |
for(int i = 0; i < l; i++) { | |
if(sir[i] >= 'a' && sir[i] <= 'z') { | |
if(E(alt, sir[i])) { | |
alt[k] = sir[i]; | |
k++; | |
} | |
} | |
} | |
alt[k] = '\0'; | |
l = strlen(alt); | |
for(int i = 0; i < l; i++) | |
cout << alt[i] << " "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001]; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
for(int i=1;i<=n;i++) { | |
if(v[i] % 2 != 0) { | |
cout << v[i] << " "; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
unsigned long long factorial(int n) { | |
unsigned long long p = 1; | |
for(int i = 1; i <= n; i++) | |
p *= i; | |
return p; | |
} | |
int main() { | |
int n, x; | |
cin >> n; | |
for(int i = 1; i <= n; i++) { | |
cin >> x; | |
if(factorial(n) % x == 0) | |
cout << x << " "; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, a, p=1, P=1; | |
const int numar = 10; | |
cin >> n >> a; | |
while(a != 0) { | |
P = P * numar; | |
a--; | |
} | |
p = n * P; | |
cout << p; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int parte_intreaga(double n) { | |
return int(n); | |
} | |
int main() { | |
int n, v[1000], elNenule=0, sumaElNenule=0, Ma, k; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
for(int i=1;i<=n;i++) { | |
if(v[i] != 0) { | |
elNenule++; | |
sumaElNenule += v[i]; | |
} | |
} | |
Ma = sumaElNenule / elNenule; | |
k = parte_intreaga(Ma); | |
for(int i=1;i<=n;i++) { | |
if(v[i] == 0) v[i] = k; | |
} | |
for(int i=1;i<=n;i++) | |
cout << v[i] << " "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
if(n > 0) | |
cout << "pozitiv"; | |
else if(n<0) | |
cout << "negativ"; | |
else | |
cout << "nul"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b, P=1; | |
cin >> a >> b; | |
while(b != 0) { | |
P *= a; | |
b--; | |
} | |
cout << P; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, s=0; | |
cin >> n; | |
while(n) { | |
s = s + n % 10; | |
n = n / 10; | |
} | |
cout << s; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int G, O, C, P; | |
cin >> G >> O; | |
C = G + O; | |
P = G * 2 + O * 4; | |
cout << C << " " << P; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
if((n % 4 == 0 && n % 100 != 0) || n % 400 == 0) | |
cout << "bisect"; | |
else | |
cout << "nebisect"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "math.h" | |
using namespace std; | |
int main() { | |
int n, pp; | |
cin >> n; | |
pp = sqrt(n); | |
if(pp*pp == n) | |
cout << "da"; | |
else | |
cout << "nu"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int l, Al, V; | |
cin >> l; | |
Al = 6 * (l*l); | |
V = l * l * l; | |
cout << Al << " " << V; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, cifra; | |
cin >> n; | |
cifra = (n/100)*10+n%10; | |
cout << cifra; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <queue> | |
using namespace std; | |
ifstream in("alee.in"); | |
ofstream out("alee.out"); | |
int matriceLee[180][180], n, m; | |
int startx, starty, stopx, stopy; | |
int di[4] = {0, 0, -1, 1}; | |
int dj[4] = {1, -1, 0, 0}; | |
queue < pair < int, int > > Coada; | |
void Citire_Date() { | |
in >> n >> m; | |
for(int i = 1; i <= m; i++) { | |
int x, y; | |
in >> x >> y; | |
matriceLee[x][y] = -1; | |
} | |
in >> startx >> starty; | |
in >> stopx >> stopy; | |
in.close(); | |
} | |
bool OK(int i, int j) { | |
if(i < 1 || j < 1 || i > n || j > n) return false; | |
if(matriceLee[i][j] == -1) return false; | |
return true; | |
} | |
void aglLee() { | |
int i, j, i_urmator, j_urmator; | |
matriceLee[startx][starty] = 1; | |
Coada.push(make_pair(startx, starty)); | |
while(!Coada.empty()) { | |
i = Coada.front().first; | |
j = Coada.front().second; | |
Coada.pop(); | |
for(int d = 0; d < 4; d++) { | |
i_urmator = i + di[d]; | |
j_urmator = j + dj[d]; | |
if(OK(i_urmator, j_urmator) && matriceLee[i_urmator][j_urmator] == 0) { | |
matriceLee[i_urmator][j_urmator] = matriceLee[i][j] + 1; | |
Coada.push(make_pair(i_urmator, j_urmator)); | |
} | |
} | |
} | |
} | |
int main() { | |
Citire_Date(); | |
aglLee(); | |
out << matriceLee[stopx][stopy]; | |
out.close(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
long long int n; | |
cin >> n; | |
cout << (n-1) * (n) / 2; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int n, k, cnt=0; | |
cin>>n>>k; | |
while(n>9){ | |
cnt++; | |
n/=10; | |
} | |
cout<<1; | |
for(int i=1; i<=k; i++) | |
for(int j=1; j<=cnt; j++) | |
cout<<0; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int t1, t2, n, m, z; | |
cin >> t1 >> t2 >> n >> m >> z; | |
cout << (t1*n + t2*m) * z; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
int s = n / 10 + n % 10; | |
cout << s; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, c, maximImp=0; | |
cin >> n; | |
while(n!=0) { | |
c = n % 10; | |
n = n / 10; | |
if(c % 2 != 0) { | |
if(c > maximImp) { | |
maximImp = c; | |
} | |
} | |
} | |
if(maximImp > 0) | |
cout << maximImp; | |
else | |
cout << "nu exista"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
ifstream cin("sume.in"); | |
ofstream cout("sume.out"); | |
int main() | |
{ | |
int n, a[101], k=0, s=0; | |
cin>>n; | |
for(int i=1; i<=n; i++) cin>>a[i]; | |
while(k<n){ | |
s=0; | |
for(int i=1; i<=n-k; i++) s+=a[i]; | |
cout<<s<<"\n"; | |
k++; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
ifstream in("pozitie.in"); | |
ofstream out("pozitie.out"); | |
int main() { | |
int n, v[10000], copie; | |
in >> n; | |
int k = 0; | |
for(int i = 1; i <= n; i++) { | |
in >> v[i]; | |
if(v[i] < v[1]) k++; | |
} | |
out << k+1; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
ifstream in("pozitiex.in"); | |
ofstream out("pozitiex.out"); | |
int main() { | |
int n, x, v[10001], k = 0; | |
bool exista = false; | |
in >> x >> n; | |
for(int i = 1; i <= n; i++) { | |
in >> v[i]; | |
if(v[i] == x) exista = true; | |
if(v[i] < x) k++; | |
} | |
if(exista == false) out << "NU EXISTA"; | |
else out << k+1; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, prim_i, doi_i; | |
cin >> n; | |
int i = 1; | |
while(i <= n) { | |
if(i < n) { | |
int aux = prim_i; | |
prim_i = i; | |
doi_i = aux; | |
} | |
i+=2; | |
} | |
cout << doi_i << " " << prim_i; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
if(n%2==0) | |
n += 2; | |
else n+=1; | |
cout << n << " " << n + 2; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
int main() { | |
int n, v[1000]; | |
cin >> n; | |
for(int i = 0; i < n; i++) cin >> v[i]; | |
for(int i = 0; i < n; i++) { | |
if(sqrt(v[i]) == int(sqrt(v[i]))) cout << "DA" << endl; | |
else cout << "NU" << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
double n; | |
cin >> n; | |
cout << int(n) % 10; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int n, m, v[105], x[105]; | |
bool f(int a) { | |
for(int i = 1; i <= m; i++) | |
if(a <= x[i]) return false; | |
return true; | |
} | |
int main() { | |
cin >> n; | |
for(int i = 1; i <= n; i++) | |
cin >> v[i]; | |
cin >> m; | |
for(int i = 1; i <= m; i++) | |
cin >> x[i]; | |
int C = 0; | |
for(int i = 1; i <= n; i++) | |
if(f(v[i])) C++; | |
cout << C; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, m; | |
cin >> n >> m; | |
n = n + m; | |
m = n - m; | |
n = n - m; | |
cout << n << " " << m; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
using namespace std; | |
int main() { | |
char sir[14]; | |
cin >> sir; | |
for(int i = 1; i < 7; i+=2) | |
cout << sir[i] << sir[i+1] << " "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cout << i << " "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[100], S=1; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
int MIN, MAX; | |
MIN = v[1]; | |
MAX = v[2]; | |
for(int i=1;i<=n;i++) { | |
if(v[i] > MAX) MAX = v[i]; | |
if(v[i] < MIN) MIN = v[i]; | |
} | |
S = MIN + MAX; | |
cout << S; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
int main() { | |
int n, j = 1; | |
cin >> n; | |
while(j <= n) { | |
for(int i = 1; i <= j; i++) | |
cout << i << " "; | |
cout << endl; | |
j++; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001]; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
int MAX; | |
MAX = v[1]; | |
for(int i=1;i<=n;i++) { | |
if(MAX < v[i]) | |
MAX = v[i]; | |
} | |
cout << MAX; | |
// aici se putea rezolva la fel de usor si fara vectori, dar nah | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001]; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
int MIN; | |
MIN = v[1]; | |
for(int i=1;i<=n;i++) { | |
if(MIN > v[i]) | |
MIN = v[i]; | |
} | |
cout << MIN; | |
// aici se putea rezolva la fel de usor si fara vectori, dar nah | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
cin>>n; | |
if(n == 1) | |
{ | |
cout<<2; | |
return 0; | |
} | |
if(n % 2 == 0) | |
n++; | |
else | |
n += 2; | |
while(true) | |
{ | |
if(n > 1 && (n % 2 != 0 || n == 2)) | |
{ | |
int sq = sqrt(n), d; | |
for(d = 3; d <= sq; d += 2) | |
if(n % d == 0) | |
break; | |
if(d > sq) | |
break; | |
} | |
n += 2; | |
} | |
cout<<n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool prim(int n) { | |
if(n < 2) return false; | |
if(n == 2) return true; | |
if(n % 2 == 0) return false; | |
for(int d = 3; d * d <= n; d+= 2) | |
if(n % d == 0) return false; | |
return true; | |
} | |
int cifre(int n) { | |
int s = 0; | |
while(n) {n=n/10;s++;} | |
return s; | |
} | |
int main() { | |
int n, s = 0; | |
long int nr; | |
cin >> n; | |
while(n) { | |
cin >> nr; | |
if(prim(nr)) { | |
s += cifre(nr); | |
} | |
n--; | |
} | |
cout << s; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool prim(int n) { | |
if(n < 2) return false; | |
if(n == 2) return true; | |
if(n % 2 == 0) return false; | |
for(int d = 3; d * d <= n; d+= 2) | |
if(n % d == 0) return false; | |
return true; | |
} | |
int cifre(int n) { | |
int s = 0; | |
while(n) { | |
s += n % 10; | |
n /= 10; | |
} | |
return s; | |
} | |
int main() { | |
int n, s = 0; | |
long int nr; | |
cin >> n; | |
while(n) { | |
cin >> nr; | |
if(prim(nr)) { | |
s += cifre(nr); | |
} | |
n--; | |
} | |
cout << s; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, inv=0, D=0; | |
cin >> n; | |
while(n!=0) { | |
inv = inv * 10 + n % 10; | |
n = n / 10; | |
} | |
for(int i=1;i<=inv;i++) { | |
if(inv % i == 0) D++; | |
} | |
cout << D; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool prim(int n) { | |
if(n < 2) return false; | |
if(n == 2) return true; | |
if(n % 2 == 0) return false; | |
for(int d = 3; d * d <= n; d+= 2) | |
if(n % d == 0) return false; | |
return true; | |
} | |
int main() { | |
int a, b, c = 0; | |
cin >> a >> b; | |
if(a > b) { | |
int aux = a; | |
a = b; | |
b = aux; | |
} | |
for(int i = a; i <= b; i++) { | |
if(prim(i)) c++; | |
} | |
cout << c; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, cateCifre=0; | |
cin >> n; | |
while(n!=0) { | |
n = n / 10; | |
cateCifre++; | |
} | |
cout << cateCifre; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
if(n <= 15) { | |
cout << n*n; | |
}else if(16 <= n && n <= 30) { | |
int suma=0; | |
while(n!=0) { | |
suma += n%10; | |
n=n/10; | |
} | |
cout << suma; | |
}else { | |
int p=1; | |
while(n!=0){ | |
p *= n % 10; | |
n = n / 10; | |
} | |
cout << p; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, c, cifreImpare = 0; | |
cin >> n; | |
while(n!=0) { | |
c = n % 10; | |
if(c % 2 != 0) cifreImpare++; | |
n = n / 10; | |
} | |
cout << cifreImpare; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
int main() { | |
int n; | |
char c; | |
cin >> n >> c; | |
int j = 1; | |
while(j <= n) { | |
for(int i = 1; i <= j; i++) | |
cout << c; | |
cout << endl; | |
j++; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, S=0; | |
cin >> n; | |
for(int i=1;i<=n*2;i++) { | |
if(i%2==0) S+=i; | |
} | |
cout << "Suma este " << S; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b, x; | |
cin >> a >> b >> x; | |
// [a;b], x <= a si b <= x | |
if(a <= x && x <= b) | |
cout << "DA"; | |
else | |
cout << "NU"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001], suma = 0, Ma, C=0; | |
cin >> n; | |
for(int i=1;i<=n;i++) { | |
cin >> v[i]; | |
suma += v[i]; | |
} | |
Ma = suma / n; | |
for(int i=1;i<=n;i++) { | |
if(v[i] > Ma) C++; | |
} | |
cout << C; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int sum_cifre(int n) { | |
int s = 0; | |
while(n) { | |
s += n % 10; | |
n = n / 10; | |
} | |
return s; | |
} | |
int main() { | |
int n, y[205], x[205]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) { | |
cin >> x[i]; | |
y[i] = x[i] % sum_cifre(x[i]); | |
} | |
for(int i = 1; i <= n; i++) | |
cout << y[i] << " "; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool prim(int n) { | |
if(n < 2) | |
return false; | |
if(n == 2) | |
return true; | |
if(n % 2 == 0) | |
return false; | |
for(int d = 3; d * d <= n; d+=2) | |
if(n % d == 0) | |
return false; | |
return true; | |
} | |
int main() { | |
int n, v[205]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) | |
cin >> v[i]; | |
for(int i = n; i >= 1; i--) | |
if(prim(v[i])) cout << v[i] << " "; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int cmmdc(int a, int b) { | |
while(b != 0) { | |
int r = a % b; | |
a = b; | |
b = r; | |
} | |
return a; | |
} | |
int main() { | |
int n, v[205]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) | |
cin >> v[i]; | |
int C = 0, ultim = v[n]; | |
for(int i = 1; i < n; i++) | |
if(cmmdc(v[i], ultim) == 1) | |
C++; | |
cout << C; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int cmmdc(int a, int b) { | |
while(b != 0) { | |
int r = a % b; | |
a = b; | |
b = r; | |
} | |
return a; | |
} | |
int main() { | |
int n, C = 0, v[205]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) cin >> v[i]; | |
for(int i = 1; i <= n; i++) { | |
for(int j = i + 1; j <= n; j++) { | |
if(cmmdc(v[i], v[j]) == 1) | |
C++; | |
} | |
} | |
cout << C; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int sum_cifre(int n) { | |
int s = 0; | |
while(n) { | |
s += n % 10; | |
n = n / 10; | |
} | |
return s; | |
} | |
int main() { | |
int n, C = 0, v[205]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) cin >> v[i]; | |
for(int i = 1; i <= n; i++) { | |
for(int j = i + 1; j <= n; j++) { | |
if(sum_cifre(v[i]) == sum_cifre(v[j])) | |
C++; | |
} | |
} | |
cout << C; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int n, a[10000], diferit=1; | |
cin>>n; | |
for(int i=0; i<n; i++) cin>>a[i]; | |
for(int i=1; i<n-1; i++){ | |
for(int j=i+1; j<n; j++) | |
if(a[i]==a[j]) diferit=0; | |
} | |
if(diferit==0) cout<<"NU"; | |
else cout<<"DA"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int n, m; | |
int x[25001], y[200001]; | |
int main() { | |
cin >> n; | |
for(int i = 1; i <= n; i++) cin >> x[i]; | |
cin >> m; | |
for(int i = 1; i <= m; i++) cin >> y[i]; | |
int inceput, sfarsit, mijloc; | |
for(int i = 1; i <= m; i++) { | |
inceput = 1; | |
sfarsit = n; | |
while(inceput <= sfarsit) { | |
mijloc = (inceput + sfarsit) / 2; | |
if(x[mijloc] == y[i]) { | |
cout << 1 << " "; | |
break; | |
}else { | |
if(x[mijloc] < y[i]) | |
inceput = mijloc + 1; | |
else | |
sfarsit = mijloc - 1; | |
} | |
} | |
if(inceput > sfarsit) | |
cout << 0 << " "; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001]; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
for(int i=1;i<=n;i++) { | |
for(int j=i+1;j<=n;j++) { | |
if(v[i] > v[j]) { | |
int aux = v[i]; | |
v[i] = v[j]; | |
v[j] = aux; | |
} | |
} | |
} | |
for(int i=1;i<=n;i++) | |
cout << v[i] << " "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void sortare(int a, int b, int v[], bool cresc){ | |
for(int i=a; i<b; i++) | |
for(int j=i+1; j<=b; j++) | |
if(cresc){ | |
if(v[i]>v[j]) swap(v[i], v[j]); | |
} | |
else if(v[i]<v[j]) swap(v[i], v[j]); | |
} | |
int main(){ | |
int n, k, a[1005]; | |
cin>>n>>k; | |
for(int i=1; i<=n; i++) cin>>a[i]; | |
sortare(1, k, a, 1); | |
sortare(k+1, n, a, 0); | |
for(int i=1; i<=n; i++) cout<<a[i]<<" "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int cmmdc(int x, int y){ | |
while(x!=y){ | |
if(x>y) x=x-y; | |
else y=y-x; | |
} | |
return x; | |
} | |
void bSort(int a[], int n){ | |
bool ok=true; | |
int j=0; | |
while(ok){ | |
ok=false; | |
j++; | |
for(int i=1; i<n-j+1; i++) | |
if(a[i]<a[i+1]) swap(a[i], a[i+1]), ok=true; | |
} | |
} | |
int main() | |
{ | |
int n, a[1006], k=0, v[1006]; | |
cin>>n; | |
for(int i=1; i<=n; i++) cin>>a[i]; | |
for(int i=1; i<=n; i++) | |
if(cmmdc(a[i], a[n])==1) v[++k] = a[i]; | |
bSort(v, k); | |
for(int i=1; i<=k; i++) cout<<v[i]<<" "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, MAX; | |
MAX = -2; | |
cin >> n; | |
if(n == 0) | |
cout << "NU EXISTA"; | |
else { | |
while(n != 0) { | |
cin >> n; | |
if(n > MAX) MAX = n; | |
} | |
cout << MAX; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001]; | |
cin >> n; | |
for(int i=1;i<=n;i++) { | |
cin >> v[i]; | |
} | |
for(int i=1;i<=n;i++) { | |
if(v[i] % v[n] == 0) { | |
cout << v[i] << " "; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, v[1001]; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> v[i]; | |
int maxim, minim, diferenta, cateEl=0; | |
maxim = v[1]; | |
minim = v[1]; | |
for(int i=1;i<=n;i++) { | |
if(v[i] > maxim) | |
maxim = v[i]; | |
else if(v[i] < minim) | |
minim = v[i]; | |
} | |
diferenta = maxim - minim; | |
for(int i=1;i<=n;i++) { | |
if(v[i] == diferenta) cateEl++; | |
} | |
cout << cateEl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, c_max = 0; | |
cin >> n; | |
while(n) { | |
int cifra = n % 10; | |
if(cifra > c_max) c_max = cifra; | |
n /= 10; | |
} | |
cout << c_max; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, inv=0; | |
cin >> n; | |
while(n!=0) { | |
inv = inv * 10 + n % 10; | |
n = n / 10; | |
} | |
cout << inv; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
ifstream in("maxim.in"); | |
ofstream out("maxim.out"); | |
int Maxim(int nr1, int nr2) { | |
if(nr1 > nr2) return nr1; | |
return nr2; | |
} | |
int main() { | |
int a, b, maxim; | |
in >> a >> b; | |
maxim = Maxim(a, b); | |
out << maxim; | |
in.close(); | |
out.close(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int n, mat[205][205]; | |
int valori[205], poz; | |
bool apare(int poz, int v[], int x) { | |
for(int i = 1; i <= poz; i++) | |
if(x == v[i]) return false; | |
return true; | |
} | |
void sortare() { | |
for(int i = 1; i <= poz; i++) { | |
for(int j = i + 1; j <= poz; j++) { | |
if(valori[i] > valori[j]) { | |
int aux = valori[i]; | |
valori[i] = valori[j]; | |
valori[j] = aux; | |
} | |
} | |
} | |
} | |
int main() { | |
cin >> n; | |
for(int i = 1; i <= n; i++) | |
for(int j = 1; j <= n; j++) | |
cin >> mat[i][j]; | |
for(int i = 1; i <= n; i++) { | |
for(int j = 1; j <= n; j++) { | |
if(i > j && i + j < n + 1) { | |
if(apare(poz, valori, mat[i][j])) { | |
poz++; | |
valori[poz] = mat[i][j]; | |
} | |
} | |
} | |
} | |
sortare(); | |
for(int i = 1; i <= poz; i++) | |
cout << valori[i] << " "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, mat[105][105]; | |
int S[4]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) { | |
for(int j = 1; j <= n; j++) | |
cin >> mat[i][j]; | |
} | |
for(int i = 1; i <= n; i++) { | |
for(int j = 1; j <= n; j++) { | |
if(i < j && i + j < n + 1) | |
S[0] += mat[i][j]; | |
if(i < j && i + j > n + 1) | |
S[1] += mat[i][j]; | |
if(i > j && i + j > n + 1) | |
S[2] += mat[i][j]; | |
if(i > j && i + j < n + 1) | |
S[3] += mat[i][j]; | |
} | |
} | |
for(int i = 0; i < 4; i++) { | |
for(int j = i + 1; j < 4; j++) { | |
if(S[i] > S[j]) { | |
int aux = S[i]; | |
S[i] = S[j]; | |
S[j] = aux; | |
} | |
} | |
} | |
for(int i = 0; i < 4; i++) | |
cout << S[i] << " "; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, mat[30][30]; | |
cin >> n; | |
for(int i = 1; i <= n; i++) | |
for(int j = 1; j <= n; j++) | |
cin >> mat[i][j]; | |
int i, j, k; | |
i = 0; | |
for(k = 1; k <= 2 * n - 1; k++) { | |
if(k > n) | |
i++; | |
if(k % 2 == 0) | |
for(j = k - i; j > i; j--) | |
cout << mat[j][k+1-j] << " "; | |
else | |
for(j=i+1; j<=k-i; j++) | |
cout << mat[j][k+1-j] << " "; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int x, y, a; | |
cin >> x >> y; | |
a = 3 * y - x; | |
cout << a; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b; | |
cin >> a >> b; | |
cout << b/a; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int nr_cif_zero(int n) { | |
if(n < 10 && n != 0) | |
return 0; | |
if(n == 0) | |
return 1; | |
else { | |
if(n % 10 == 0) | |
return (nr_cif_zero(n / 10) + 1); | |
else | |
return nr_cif_zero(n / 10); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int cifmax(int n) { | |
if(n <= 9) return n; | |
else { | |
int m = cifmax(n / 10); | |
if(m > n % 10) | |
return m; | |
return n % 10; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int cifmin(int n) { | |
if(n <= 9) return n; | |
else { | |
int m = cifmin(n / 10); | |
if(n % 10 < m) | |
return n % 10; | |
return m; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int nota; | |
cin >> nota; | |
if(nota >= 5) | |
cout << "promovat"; | |
else | |
cout << "corigent"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void afisvec(int v[], int n) { | |
if(n != 0) { | |
afisvec(v, n-1); | |
cout << v[n-1] << " "; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
using namespace std; | |
ifstream in("fill.in"); | |
ofstream out("fill.out"); | |
int n, m, matrice[101][101], matriceFill[101][101]; | |
int numar_zona; | |
int di[4] = {0, 0, -1, 1}; | |
int dj[4] = {1, -1, 0, 0}; | |
bool OK(int i, int j) { | |
if(i < 1 || j < 1 || i > n || j > m) return false; | |
if(matriceFill[i][j]) return false; | |
if(matrice[i][j] == 0) return false; | |
return true; | |
} | |
void algFill(int i, int j) { | |
matriceFill[i][j] = numar_zona; | |
for(int d = 0; d < 4; d++) { | |
int i_urmator = i + di[d]; | |
int j_urmator = j + dj[d]; | |
if(OK(i_urmator, j_urmator) && matrice[i_urmator][j_urmator] == matrice[i][j]) | |
algFill(i_urmator, j_urmator); | |
} | |
} | |
int main() { | |
in >> n >> m; | |
for(int i = 1; i <= n; i++) | |
for(int j = 1; j <= m; j++) | |
in >> matrice[i][j]; | |
in.close(); | |
for(int i = 1; i <= n; i++) { | |
for(int j = 1; j <= m; j++) { | |
if(!matriceFill[i][j]) { | |
if(matrice[i][j] == 1) numar_zona++; | |
algFill(i, j); | |
} | |
} | |
} | |
out << numar_zona; | |
for(int i = 1; i <= n; i++) { | |
for(int j = 1; j <= m; j++) | |
cout << matriceFill[i][j] << " "; | |
cout << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
ifstream cin("halfsort.in"); | |
ofstream cout("halfsort.out"); | |
void sortare(int a, int b, int v[], bool cresc){ | |
for(int i=a; i<b; i++) | |
for(int j=i+1; j<=b; j++) | |
if(cresc){ | |
if(v[i]>v[j]) swap(v[i], v[j]); | |
} | |
else if(v[i]<v[j]) swap(v[i], v[j]); | |
} | |
int main(){ | |
int n, a[101]; | |
cin>>n; | |
for(int i=1; i<=n; i++) cin>>a[i]; | |
sortare(1, n/2, a, 1); | |
sortare(n/2+1, n, a, 0); | |
for(int i=1; i<=n; i++) cout<<a[i]<<" "; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
#include <fstream> | |
using namespace std; | |
ifstream in("lgmax.in"); | |
ofstream out("lgmax.out"); | |
int main() { | |
int n, maxim = 0, coeficient = 0, MAX; | |
char sir[100][256]; | |
in >> n; | |
while(n) { | |
in.get(); | |
in.get(sir[coeficient], 256); | |
if(strlen(sir[coeficient]) > maxim) { | |
maxim = strlen(sir[coeficient]); | |
MAX = coeficient; | |
} | |
coeficient++; | |
n--; | |
} | |
out << sir[MAX]; | |
in.close(); | |
out.close(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int a , b , c , max , min; | |
//citim cele trei numere | |
cin >> a >> b >> c; | |
//determinam maximul | |
max = a; | |
if(max < b) | |
max = b; | |
if(max < c) | |
max = c; | |
//determinam minimul | |
min = a; | |
if(min > b) | |
min = b; | |
if(min > c) | |
min = c; | |
//determinam rezultatul cerut | |
cout << max-min << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void nr_cif_zero(int n, int &nr) { | |
if(n > 9) { | |
nr_cif_zero(n/10, nr); | |
if(n % 10 == 0) nr++; | |
}else | |
nr = !n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b, suma=0; | |
cin >> a >> b; | |
suma=a+b; | |
cout << suma; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
double v[2001], k=0, a, b; | |
int n; | |
cin>>n; | |
for(int i=1; i<=n; i++) cin>>v[i]; | |
a = v[1]; | |
b = v[n]; | |
if(b<a) swap(a, b); | |
for(int i=1; i<=n; i++) | |
if(v[i]>b || v[i]<a) k++; | |
cout<<k; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include <iostream> | |
using namespace std; | |
#define DIMEN 1001 | |
bool e_prim(int n); | |
int suma_divImp(int v[], int i, int s); | |
int exista_impar_divImp(int v[], int i, int s); | |
int suma_pare_divImp(int v[], int i, int s); | |
int exista_prime_divImp(int v[], int i, int s); | |
int cate_impare_divImp(int v[], int i, int s); | |
int toate_pare_divImp(int v[], int i, int s); | |
int maxim_prim_divImp(int v[], int i, int s); | |
int toate_egale_divImp(int v[], int i, int s); | |
int maxim_numar_divImp(int v[], int i, int s); | |
int main() { | |
int n, v[DIMEN]; | |
cin >> n; | |
for (int i = 1; i <= n; i++) | |
cin >> v[i]; | |
// :D | |
return 0; | |
} | |
int suma_divImp(int v[], int i, int s) { | |
if (i == s) | |
return v[s]; | |
int d1 = suma_divImp(v, i, (i + s) / 2); | |
int d2 = suma_divImp(v, (i + s) / 2 + 1, s); | |
return d1 + d2; | |
} | |
int exista_impar_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (v[s] % 2 == 1) | |
return 1; | |
return 0; | |
} | |
int d1 = exista_impar_divImp(v, i, (i + s) / 2); | |
int d2 = exista_impar_divImp(v, (i + s) / 2 + 1, s); | |
if (d1 || d2) | |
return 1; | |
return 0; | |
} | |
int suma_pare_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (v[s] % 2 == 0) return v[s]; | |
return 0; | |
} | |
int d1 = suma_pare_divImp(v, i, (i + s) / 2); | |
int d2 = suma_pare_divImp(v, (i + s) / 2 + 1, s); | |
return d1 + d2; | |
} | |
int exista_prime_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (e_prim(v[s])) return 1; | |
} | |
int d1 = exista_prime_divImp(v, i, (i + s) / 2); | |
int d2 = exista_prime_divImp(v, (i + s) / 2 + 1, s); | |
if (d1 || d2) return 1; | |
return 0; | |
} | |
bool e_prim(int n) { | |
if (n < 2) return false; | |
if (n == 2) return true; | |
if (n % 2 == 0) return false; | |
for (int d = 3; d * d <= n; d += 2) | |
if (n % d == 0) return false; | |
return true; | |
} | |
int cate_impare_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (v[s] % 2 == 1) | |
return 1; | |
return 0; | |
} | |
int d1 = cate_impare_divImp(v, i, (i + s) / 2); | |
int d2 = cate_impare_divImp(v, (i + s) / 2 + 1, s); | |
return d1 + d2; | |
} | |
int toate_pare_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (v[s] % 2 == 0) return 1; | |
return 0; | |
} | |
int d1 = toate_pare_divImp(v, i, (i + s) / 2); | |
int d2 = toate_pare_divImp(v, (i + s) / 2 + 1, s); | |
return d1 + d2; | |
} | |
int maxim_prim_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (e_prim(v[s])) return v[s]; | |
return 0; | |
} | |
int d1 = maxim_prim_divImp(v, i, (i + s) / 2); | |
int d2 = maxim_prim_divImp(v, (i + s) / 2 + 1, s); | |
if (d1 > d2) | |
return d1; | |
return d2; | |
} | |
int toate_egale_divImp(int v[], int i, int s) { | |
if (i == s) { | |
if (v[s] == v[1]) return 1; | |
return 0; | |
} | |
int d1 = toate_egale_divImp(v, i, (i + s) / 2); | |
int d2 = toate_egale_divImp(v, (i + s) / 2 + 1, s); | |
return d1 + d2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PROBLEME REZOLVATE CU 100 PUNCTE PENTRU SITE-UL PBINFO | |
// PROFILUL MEU: https://www.pbinfo.ro/?pagina=profil&user=Mentosan |
iti multumesc
Buna, Robert!Ai mai putea posta si alte rezolvari pb info?De ex problema 3078’65,66,1311,833,168,9.Multumesc!
Multumesc frumos pt rezolvari 👍
Problema 3398 ? Se poate?
Băieții de la Tutoriale-Pe.NET au postat rezolvările tuturor problemelor de pe PBInfo.
Click pentru rezolvări
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
41 probleme - 22.03.2019