1259 - 팰린드롬수

solution

code

#include <iostream>

using namespace std;

int main()
{
    int input;
    while(1)
    {
        cin >> input;
        if(input == 0) break;

        int i = 1;
        int cnt = 0;
        while(input / i != 0)
        {
            cnt++;
            i *= 10;
        }

        int * arr = new int[cnt];
        int div = 1;
        for(int i = 0; i < cnt - 1; i++)
            div *= 10;
        for(int i = 0; i < cnt; i++)
        {
            arr[i] = input / div;
            input -= arr[i] * div;
            div /= 10;
        }

        int start = 0;
        int end = cnt-1;
        bool palindrome = true;
        while(start <= end)
        {
            if(arr[start] != arr[end])
            {
                palindrome = false;
                break;
            }
            start++;
            end--;
        }

        if(palindrome) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}

ref

1259번: 팰린드롬수

로그인