Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("suma6.in");
  4. ofstream fout("suma6.out");
  5. int special(int a)
  6. {
  7. int aux=a,nr_cif=0;
  8. while(aux>9)
  9. {
  10. nr_cif++;
  11. aux/=10;
  12. }
  13. if(nr_cif%2==1)
  14. return 0;
  15. if(aux==a%10)
  16. return 1;
  17. return 0;
  18. }
  19. int cif_mij(int a)
  20. {
  21. int aux=a,nr_cif=0;
  22. while(aux)
  23. {
  24. nr_cif++;
  25. aux/=10;
  26. }
  27. for(int i=1; i<=nr_cif/2; i++)
  28. a/=10;
  29. return a%10;
  30. }
  31. int main()
  32. {
  33. int n,x,s=0;
  34. fin>>n;
  35. for(int i=1; i<=n; i++)
  36. {
  37. fin>>x;
  38. if(special(x))
  39. s+=cif_mij(x);
  40. }
  41. fout<<s;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement