Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Recapitulare pentru teza
- 1. Se citesc din fisier multe numere intregi, sa se memoreze intr-un vector doar elementele care incep si se termina cu
- aceeasi cifra. Sa se afiseze apoi cele mai mari 2 valori din vector.
- */
- #include <fstream>
- #include <limits>
- using namespace std;
- int main()
- {
- int n, v[100], poz(1), pc, uc, aux, max1, max2, i;
- max1 = -INT_MAX;
- max2 = -INT_MAX;
- ifstream fin("vectori.in");
- while(fin >> n)
- {
- aux = n;
- while(aux)
- {
- if(aux == n) {
- uc = aux % 10;
- aux /= 10;
- }
- else if(aux >= 0 && aux <= 9) {
- pc = aux % 10;
- aux /= 10;
- }
- else
- aux /= 10;
- }
- if(pc == uc)
- {
- v[poz] = n;
- poz++;
- }
- }
- fin.close();
- ofstream fout("vectori.out");
- for(i = 1; i <= poz; i++) {
- if(v[i] > max1) {
- max2 = max1;
- max1 = v[i];
- }
- else
- if(v[i] < max1 && v[i] > max2)
- max2 = v[i];
- }
- fout << max1 << " " << max2;
- fout << endl;
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment