Advertisement
a53

sir12

a53
Jan 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("sir12.in");
  4. ofstream g("sir12.out");
  5. int a,maxi1=-1,maxi2=-1,nr;
  6.  
  7. int main()
  8. {
  9. while (f>>a&&nr<=3) ///se citesc pe rand numere din sir pana cand nu mai sunt elemente de citit(f>>a) sau pana cand au fost citite mai mult de 3 numere impare(nr<=3)
  10. {
  11. if(a%2==1) ///daca elementul citit este impar, creste nr-ul
  12. ++nr;
  13. else
  14. {
  15. if(nr==3)
  16. {
  17. if(a>maxi1)
  18. {
  19. maxi2=maxi1;
  20. maxi1=a;
  21. }
  22. else
  23. {
  24. if(a>maxi2)
  25. maxi2=a;
  26. }
  27. }
  28. }
  29. }
  30. if(maxi1!=-1&&maxi2!=-1)
  31. g<<maxi2<<' '<<maxi1;
  32. else
  33. g<<"Nu exista";
  34. f.close();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement