Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. //Pb1
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void citire(int &n, int a[])
  6. {
  7. cin >> n;
  8. for(int i = 1; i <= n; ++i)
  9. cin >> a[i];
  10. }
  11.  
  12.  
  13. int cifEgale(int n)
  14. {
  15. int uc = n % 10;
  16. n /= 10;
  17. while(n > 0)
  18. {
  19. if(uc != n % 10)
  20. return 0;
  21. n /= 10;
  22. }
  23. return 1;
  24. }
  25.  
  26. int cifEgale2(int a, int b) //Pentru cazurile in care inaltimea e mai mare decat 9
  27. {
  28. int s = a%10 + b%10;
  29. while(a && b)
  30. {
  31. int na = a % 10;
  32. int nb = b % 10;
  33.  
  34. if(s != na + nb)
  35. return 0;
  36. a /= 10;
  37. b /= 10;
  38.  
  39. }
  40. return 1;
  41. }
  42.  
  43. int cateEgale(int n, int a[])
  44. {
  45. int cnt = 0;
  46. for(int i = 1; i < n; ++i)
  47. for(int j = i + 1; j <= n; ++j)
  48. if(cifEgale2(a[i], a[j]))
  49. cnt++;
  50. return cnt;
  51. }
  52.  
  53. int main()
  54. {
  55. int n, a[100001];
  56. citire(n, a);
  57. cout << cateEgale(n, a);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement