bogdanNiculeasa

Test 1 Culegere Bac - Subiectul III - Ex 3

Nov 25th, 2023
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream> // file stream
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.     ifstream fin("bac.in"); // input file stream
  9.     ofstream fout("bac.out");
  10.     int numarAparitii = 1;
  11.     int numarCurent, numarAnterior;
  12.     fin >> numarCurent;
  13.     numarAnterior = numarCurent;
  14.  
  15.     while (fin >> numarCurent) {
  16.         if (numarCurent == numarAnterior) {
  17.             numarAparitii++;
  18.         } else {
  19.             fout << numarAnterior << " " << numarAparitii << endl;
  20.             numarAnterior = numarCurent;
  21.             numarAparitii = 1;
  22.         }
  23.     }
  24.  
  25.     fout << numarAnterior << " " << numarAparitii << endl;
  26.  
  27.  
  28.     fin.close();
  29.     fout.close();
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment