Advertisement
Niloy007

Sum of Digit is Pallindrome or not

Mar 12th, 2021
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. // { Driver Code Starts
  2. // Initial Template for C++
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7.  // } Driver Code Ends
  8. // User function Template for C++
  9.  
  10. class Solution {
  11.   public:
  12.     int isDigitSumPalindrome(int N) {
  13.         int sum = 0;
  14.         while (N > 0) {
  15.             sum += N % 10;
  16.             N /= 10;
  17.         }
  18.         string ans = to_string(sum);
  19.         string temp = ans;
  20.         reverse(ans.begin(), ans.end());
  21.         if (ans == temp) {
  22.             return 1;
  23.         } else {
  24.             return 0;
  25.         }
  26.     }
  27. };
  28.  
  29. // { Driver Code Starts.
  30. int main() {
  31.     int t;
  32.     cin >> t;
  33.     while (t--) {
  34.         int N;
  35.         cin >> N;
  36.         Solution ob;
  37.         cout << ob.isDigitSumPalindrome(N) << "\n";
  38.     }
  39. }
  40.   // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement