varianta 12 sub 3 exercitiul 3
Răspunsuri la întrebare
#include <iostream>
#include <fstream>
using namespace std;
ifstream f1("NR1.TXT");
ifstream f2("NR2.TXT");
int main()
{
int nr1=-1, nr2=-1;
while(!f1.eof() || !f2.eof())
{
if(nr1==nr2){
if(f2.eof()){ while(f1>>nr1) if(nr1%5==0) cout<<nr1<<' '; break;}
if(f1.eof()){ while(f2>>nr2) if(nr2%5==0) cout<<nr2<<' '; break;}
while(f1>>nr1 && nr1%5!=0) continue;
while(f2>>nr2 && nr2%5!=0) continue;
}
else if(nr1>nr2)
if(!f2.eof())
while(f2>>nr2 && nr2%5!=0) continue;
else{ cout<<nr1<<' ';
while(!f1.eof()) if(nr1%5==0) cout<<nr1<<' '; break;
}
else
if(!f1.eof())
while(f1>>nr1 && nr1%5!=0) continue;
else{ cout<<nr2<<' ';
while(!f2.eof()) if(nr2%5==0) cout<<nr2<<' '; break;
}
if(nr1%5==0 && nr2%5==0){
if(nr1>nr2) cout<<nr2<<' ';
else if(nr1<nr2) cout<<nr1<<' ';
}
else if(nr1%5==0 && nr2%5!=0){ cout<<nr1<<' '; while(f1>>nr1) if(nr1%5==0) cout<<nr1<<' ';}
else if(nr1%5!=0 && nr2%5==0){ cout<<nr2<<' '; while(f2>>nr2) if(nr2%5==0) cout<<nr2<<' ';}
}
return 0;
}