Advertisement
RusSimona

Varianta87 Sub3 Ex4

Mar 12th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string.h>
  4. #include<cmath>
  5.  
  6. using namespace std;
  7. ifstream fin("NUMERE.IN");
  8.  
  9. int suma(int n)
  10. {
  11. int Sp=0, Si=0;
  12. while(n)
  13. {
  14. if(n%10%2)
  15. Si=Si+n%10;
  16. else
  17. Sp=Sp+n%10;
  18. n=n/10;
  19. }
  20.  
  21. if(Si==Sp)
  22. return 1;
  23. else
  24. return 0;
  25. }
  26.  
  27.  
  28.  
  29. int main()
  30. {
  31. int x, minim=INT_MAX, pozitie=0;
  32. while(fin>>x)
  33. {
  34. if(suma(x))
  35. {
  36. if(minim>x)
  37. {
  38. minim=x;
  39. pozitie=1;
  40. }
  41. else
  42. if(minim==x)
  43. pozitie++;
  44. }
  45. }
  46. cout<<minim<<" "<<pozitie;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement