Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream f("sir12.in");
- ofstream g("sir12.out");
- int a,maxi1=-1,maxi2=-1,nr;
- int main()
- {
- 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)
- {
- if(a%2==1) ///daca elementul citit este impar, creste nr-ul
- ++nr;
- else
- {
- if(nr==3)
- {
- if(a>maxi1)
- {
- maxi2=maxi1;
- maxi1=a;
- }
- else
- {
- if(a>maxi2)
- maxi2=a;
- }
- }
- }
- }
- if(maxi1!=-1&&maxi2!=-1)
- g<<maxi2<<' '<<maxi1;
- else
- g<<"Nu exista";
- f.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement