Rezolvare BAC Informatica 2009 – Varianta 19 – Subiectul al III-lea problema 4

Mai jos puteti gasi rezolvarea problemei 4 de la subiectul III din varianta 19 pentru examenul de bacalaureat din anul 2009

Rezolvare:

#include <fstream.h>
void main() {
ifstream f("nr1.txt"), g("nr2.txt");
int x, y, n, m, i, j;
f >> n;
g >> m;
i = j = 1;
f >> x;
g >> y;
while (i <= n && j <= m)
if (x < y) {
cout << x << " ";
f >> x;
i++;
} else if (y < x) {
cout << y << " ";
g >> y;
j++;
} else {
cout << x << " ";
f >> x;
g >> y;
i++;
j++;
}
while (i <= n) {
cout << x << " ";
f >> x;
i++;
}
while (j <= m) {
cout << y << " ";
g >> y;
j++;
}
}

Spor la lucru! Daca aveti intrebari nu ezitati sa le lasati in comentarii, va vom raspunde cat de repede putem 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *