백준 1259 팰린드롬수

윤재학·2022년 6월 30일

백준

목록 보기
3/8

reverse 함수는 algorithm 라이브러리의 포함되어있으며
의미 그대로 거꾸로 뒤집는 동작을 한다.

진행 순서

  • pelindrome 이 0일 경우 반복문 탈출을 한다.

  • reverse를 하기전 값을 temp에 저장시킨다.

  • 만약 문자열을 뒤집고도 temp와 같다면 YES

  • 같지 않다면 NO를 출력한다.

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

int main()
{
    while (true) 
    {
        string pelindrome;
        cin >> pelindrome; // 입력

        if (pelindrome == "0") break; // 0 일 경우 탈출

        string temp = pelindrome;

        reverse(pelindrome.begin(), pelindrome.end());

        if (temp == pelindrome)
        {
            cout << "yes" << endl;
        }
        else 
        {
            cout << "no" << endl;;
        }
    }

    return 0;
}

EX) 백터를 이용한 문제풀이법

profile
노력하자 즐겁게 개발할수 있는 환경을 위해

0개의 댓글