[백준/C++] 3062 - 수 뒤집기

orangesnail·2025년 8월 26일

백준

목록 보기
161/169

https://www.acmicpc.net/problem/3062


#include <iostream>
#include <string>
using namespace std;

bool isPal(int a) {
    string s = to_string(a);
    int left = 0, right = (int)s.size() - 1;

    while (left < right) {
        if (s[left] != s[right]) return false;
        left++, right--;
    }
    return true;
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        int rev = 0;
        int temp = n;

        while (temp > 0) {
            rev = rev * 10 + (temp % 10);
            temp /= 10;
        }

        int sum = n + rev;
        if (isPal(sum)) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글