Advertisement
a53

ParImpar2

a53
Nov 26th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int P,I;
  7. ifstream f("parimpar2.in");
  8. ofstream g("parimpar2.out");
  9. f>>I>>P;
  10. int n,NrP=0,NrI=0,p,i;
  11. bool gasitP=false,gasitI=false;
  12. while(f>>n)
  13. {
  14. if(n%2==0)
  15. ++NrP;
  16. else
  17. ++NrI;
  18. if(NrP==P&&!gasitP)
  19. p=n,gasitP=true;
  20. if(NrI==I&&!gasitI)
  21. i=n,gasitI=true;
  22. }
  23. f.close();
  24. if(NrP<P||NrI<I)
  25. g<<"Nu Exista";
  26. else
  27. g<<p<<' '<<i<<'\n';
  28. g.close();
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement