문자열
팰린드롬수
4gats
2023. 6. 21. 14:03
https://www.acmicpc.net/problem/1259
1259번: 팰린드롬수
입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다.
www.acmicpc.net
<algorithm> 헤더 파일에 reverse() 함수를 활용하면 문제를 쉽게 풀 수 있다.
기억해두자
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s;
//0이 아니면 무한 반복
while (s != "0") {
cin >> s;
string buf = s; // 원래 문자열 저장
reverse(s.begin(), s.end()); //앞 뒤 바꿈
if (s == "0")
break;
else if (s == buf)
cout << "yes\n";
else
cout << "no\n";
}
return 0;
}
|
cs |