fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. bool valid(int n){
  5. // check palindrome
  6. int temp = n, rev = 0;
  7. while(temp > 0){
  8. rev = rev * 10 + temp % 10;
  9. temp /= 10;
  10. }
  11. return n == rev; // return true if n is a palindrome
  12. }
  13. void sol(){
  14. int n;
  15. cin >> n;
  16. int a[n];
  17. for(int &i:a) cin >> i;
  18. int mx = 0;
  19. for(int i = 0; i < n; i++){
  20. if(valid(a[i])) mx += a[i];
  21. }
  22. cout << mx << endl;
  23. }
  24. signed main(){
  25. ios_base::sync_with_stdio(false);
  26. cin.tie(NULL);
  27. cout.tie(NULL);
  28. int t = 1;
  29. cin >> t;
  30. while(t--){
  31. sol();
  32. }
  33. return 0;
  34. }
Runtime error #stdin #stdout 0.02s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty