Advertisement
Guest User

Lungime subsir numere pare consecutive

a guest
Dec 18th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int n, x, v[69];
  7.  
  8. void citire()
  9. {
  10.     ifstream f("input.txt");
  11.     while (f >> x)
  12.     {
  13.         n++;
  14.         v[n] = x;
  15.     }
  16.     f.close();
  17. }
  18.  
  19. void determinare()
  20. {
  21.     int i, maxim = 0, lungime = 0, pozinceput;
  22.     for (i = 1; i < n; i++)
  23.     {
  24.         if (v[i] % 2 == 0)
  25.             lungime++;
  26.         else
  27.             lungime = 0;
  28.  
  29.         if (lungime > maxim)
  30.         {
  31.             maxim = lungime;
  32.             pozinceput = i - lungime;
  33.         }
  34.     }
  35.     for (i = 1; i <= maxim; i++)
  36.         cout << v[i + pozinceput] << " ";
  37.  
  38.     cout << "\nSubsirul de lungime maxima cu numere pare consecutive este de lungime " << maxim << " incepand pe pozitia " << pozinceput + 1 << endl;
  39. }
  40.  
  41. int main()
  42. {
  43.     citire();
  44.     determinare();
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement