문제
https://www.acmicpc.net/problem/1259
1259번: 팰린드롬수
입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다.
www.acmicpc.net
소스코드
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
while(1){
string s;
cin>>s;
if(s=="0") break;
string temp=s;
reverse(s.begin(),s.end());
if(temp==s){
cout<<"yes\n";
}
else{
cout<<"no\n";
}
}
return 0;
}
해설
초기 문자열과 반대의 문자열이 같으면 yes 다르면 no를 출력해주면된다.
알고리즘 헤더를 사용해서 쉽게해결할 수 있다.
'Algorithm > 구현' 카테고리의 다른 글
[백준] C++ 알고리즘 7568번 - 덩치문제 (0) | 2021.09.10 |
---|---|
[백준] 알고리즘 1193번 - 분수찾기문제 (0) | 2021.09.09 |
[백준] 알고리즘 5622번 - 다이얼문제 (0) | 2021.09.08 |