Lucian_Adrian

#499 Numarare5

Dec 4th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int v[201];
  6.  
  7. int sumacif(int m)
  8.  
  9. {
  10.  
  11. int s=0;
  12.  
  13. while (m!=0)
  14.  
  15. {
  16.  
  17. s=s+m%10; m=m/10;
  18.  
  19. }
  20.  
  21. return s;
  22.  
  23. }
  24.  
  25. int main()
  26.  
  27. {
  28.  
  29. int n, i, j, k=0;
  30.  
  31. cin >> n;
  32.  
  33. for (i=1; i<=n; ++i) cin >> v[i];
  34.  
  35. for (i=1; i<n; ++i)
  36.  
  37. for (j=i+1; j<=n; ++j)
  38.  
  39. if (sumacif(v[i])==sumacif(v[j])) ++k;
  40.  
  41. cout << k;
  42.  
  43. return 0;
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment