Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

PROB 9 REZOLVARI

1
#include <iostream>
using namespace std;
int main() {
int n, a[1001], S[1001];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int aux = a[i], s = 0;
while (aux) {
s += aux % 10;
aux /= 10;
}
S[i] = s;
}
for (int i = 1; i < n; i++)
for (int j = i + 1; j <= n; j++)
if (S[i] % 2 == 0 and S[j] % 2 == 0 and a[i]<a[j] or S[i]
% 2 == 1 and S[j] % 2 == 1 and a[i]>a[j]) swap(a[i], a[j]);

for (int i = 1; i <= n; i++)cout << a[i] << ' ';


return 0;
}

2
#include <iostream>
using namespace std;
int main() {
int n, v[1001], mij, aux1, aux2, nr = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
mij = n / 2;
for (int i = 1; i <= mij; i++) {
aux1 = v[i];
aux2 = v[n - i + 1];
while (aux1 > 9) aux1 /= 10;
while (aux2 > 9)aux2 /= 10;
if (aux1 == aux2) nr++;
}
cout << nr;
return 0;
}

3
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int main() {
int n, v[1001], max = 0, min = 100000, pozmax, pozmin;
fin >> n;
for (int i = 1; i <= n; i++) fin >> v[i];
for (int i = 1; i <= n; i++) {
if (v[i] < min)min = v[i];
if (v[i] > max)max = v[i];
}
for (int i = 1; i <= n; i++) {
if (v[i] == min)pozmin = i;
if (v[i] == max)pozmax = i;
}

if (pozmax > pozmin) {


for (int i = 1; i < pozmin; i++) fout << v[i] << ' ';
for (int i = pozmax; i >= pozmin; i--) fout << v[i] << ' ';
for (int i = ++pozmax; i <= n; i++) fout << v[i] << ' ';
}

else {
for (int i = 1; i < pozmax; i++) fout << v[i] << ' ';
for (int i = pozmin; i >= pozmax; i--) fout << v[i] << ' ';
for (int i = ++pozmin; i <= n; i++) fout << v[i] << ' ';
}

fin.close();
fout.close();
return 0;
}

4
#include <iostream>
using namespace std;
int main() {
int n, v[1001], ok = 1;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i < n; i++) if (v[i] % 2 == v[i+1] % 2) ok = 0;
if (ok) cout << "DA";
else cout << "NU";
return 0;
}

5 (NEREZOLVATA)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("interpare.in");
ofstream fout("interpare.out");
int main() {
int n, m, a[1001], b[1001], c[2002], auxa[1001], auxb[1001], poza=1,
pozb=1, k=0;
fin >> n >> m;
for (int i = 1; i <= n; i++) {
fin >> a[i];
if (a[i] % 2 == 0) {
auxa[poza] = a[i];
poza++;
}
}
for (int i = 1; i <= m; i++) {
fin >> b[i];
if (b[i] % 2 == 0) {
auxb[pozb] = b[i];
pozb++;
}
}

for (int i = 1; i <= poza; i++) cout << auxa[i] <<' ';
for (int i = 1; i <= pozb; i++)cout << auxb[i]<<' ';

int i = 1, j = 1;
while (i < poza and j < pozb)
if (auxa[i] < auxb[j]) c[++k] = auxa[i++];
else c[++k] = auxb[j++];

while (i < poza) c[++k] = auxa[i++];


while (j < pozb) c[++k] = auxb[j++];

for (int i = 1; i <= k; i++) fout << c[i]<<' ';


fin.close();
fout.close();
return 0;

6
#include <iostream>
using namespace std;
int main() {
int n, v[1001], nr2 = 0, nr5 = 0, aux;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
aux = v[i];
while (aux % 2 == 0) {
aux /= 2;
nr2++;
}
aux = v[i];
while (aux % 5 == 0) {
aux /= 5;
nr5++;
}
}
if (nr2 < nr5)cout << nr2;
else cout <<nr5;
return 0;
}

7
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("interclasare.in");
ofstream fout("interclasare.out");
int main() {
long long n, m, a[100001], b[100001], c[200001], k = 0;
fin >> n;
for (int i = 1; i <= n; i++)fin >> a[i];

fin >> m;
for (int i = 1; i <= m; i++)fin >> b[i];

int i = 1, j = 1;
while (i <= n and j <= m) {
if (a[i] < b[j]) c[++k] = a[i++];
else c[++k] = b[j++];
}
while (i <= n) c[++k] = a[i++];
while (j <= m) c[++k] = b[j++];

for (int i = 1; i <= m + n; i++) {


fout << c[i] << ' ';
if (i % 10 == 0) fout << endl;
}

fin.close();
fout.close();
return 0;
}

You might also like