알고리즘
[C++]백준 1259번: 팰린드롬수
Kwoncorin
2020. 6. 1. 17:27
728x90
https://www.acmicpc.net/problem/1259
1259번: 팰린드롬수
문제 어떤 단어를 뒤에서부터 읽어도 똑같다면 그 단어를 팰린드롬이라고 한다. 'radar', 'sees'는 팰린드롬이다. 수도 팰린드롬으로 취급할 수 있다. 수의 숫자들을 뒤에서부터 읽어도 같다면 그 ��
www.acmicpc.net
1. 문제 설명
10988번(https://kwoncorin.tistory.com/10)이랑 유사한 문제이다. 앞으로 읽은 것과 뒤로 읽은 것이 같다면 팰린드롬수이다. 10988번과 다른 것은 0이 들어올 때까지 계속해서 입력을 받는다는 것인데 do while문을 사용하여 해결할 수 있다.
2. 코드
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
do{
bool check=true;
int str_len;
cin >> input;
if(input=="0")
break;
str_len=input.length();
for(int x=0;x<str_len/2;x++)
{
if(input[x]!=input[str_len-x-1])
{
check=false;
break;
}
}
if(check)
cout <<"yes\n";
else
cout <<"no\n";
}while(true);
return 0;
}
728x90