반응형
문제 출처 :
https://www.acmicpc.net/problem/13235
알고리즘 분석 :
문제 해결에 필요한 사항
1. String :: http://www.crocus.co.kr/503
2. Reverse
3. 팰린드롬의 개념
팰린드롬이란 것은 결국 앞에서 읽거나 뒤에서 읽었을 때 같다면 팰린드롬이라는 것이다.
"다시합시다"는 팰린드롬이다.
"다시합니다"는 팰린드롬이 아니다.
이 이유를 알아보면
"다시합시다"를 거꾸로 뒤집으면 "다시합시다" 이지만, "다시합니다"를 거꾸로 뒤집으면 "다니합시다"이다.
결국 팰린드롬은 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 | #include <iostream> #include <cstdio> #include <algorithm> #include <string> using namespace std; int main() { string str; cin >> str; string tmp = str; reverse(tmp.begin(), tmp.end()); if (str.compare(tmp) == 0) cout << "true"; else cout << "false"; return 0; } // This source code Copyright belongs to Crocus // If you want to see more? click here >> | Crocus |
반응형
'Applied > 알고리즘 문제풀이' 카테고리의 다른 글
[10973번] 이전 순열 (0) | 2017.06.20 |
---|---|
[10972번] 다음 순열 (0) | 2017.06.20 |
[6081번] Hay Expenses (0) | 2017.06.20 |
[3584번] 가장 가까운 공통 조상 (0) | 2017.06.17 |
[2110번] 공유기 설치 (0) | 2017.06.17 |