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) 백터를 이용한 문제풀이법