본문 바로가기

PS/BOJ

[C++] BOJ (백준) 1259 : 팰린드롬수

문제

1259번: 팰린드롬수 (acmicpc.net)

 

1259번: 팰린드롬수

입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다.

www.acmicpc.net

코드
#include <iostream>
#include <algorithm>

using namespace std;

string chk(const string &s) {
    string tmp = s;
    reverse(tmp.begin(), tmp.end());
    if (s == tmp) return "yes";
    return "no";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;

    while (s != "0") {
        cout << chk(s) << '\n';
        cin >> s;
    }
    return 0;
}

 

설명

각 문자열이 뒤집은 문자열과 같다면 yes를 출력한다.