문제 링크입니다: https://www.acmicpc.net/problem/10174
10174번: 팰린드롬
문제 팰린드롬은 앞으로 읽으나 뒤로 읽으나 똑같은 단어나 숫자들을 말한다. 일반적으로 대소문자를 구분하지 않지만, 공백은 구분한다. 다음은 팰린드롬의 예시이다. Anna Harrah Arora Nat tan 9998999 123 321 \$\$\$&&\$\$\$ 모든 라인에 대해 팰린드롬인지 아닌지를 구분하는 프로그램을 작성하시오. 입력 첫째 줄에 테스트 케이스의 개수 n이 주어진다. 각 테스트 케이스는 한 줄의 텍스트로 이루어져있으며, 비어있는 줄은 없
www.acmicpc.net
일반적으로 대소문자를 구분하지 않는다고 하였으므로 toupper 메서드를 사용했습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main(void) | |
{ | |
int N; | |
cin >> N; | |
string flushBuffer; | |
getline(cin, flushBuffer); | |
for (int n = 0; n < N; n++) | |
{ | |
string s; | |
getline(cin, s); | |
bool flag = true; | |
for(int i=0; i<s.length() / 2; i++) | |
if (toupper(s[i]) != toupper(s[s.length() - i - 1])) | |
{ | |
flag = false; | |
break; | |
} | |
if (flag) | |
cout << "Yes\n"; | |
else | |
cout << "No\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 9376번 탈옥 (6) | 2019.07.31 |
---|---|
백준 1015번 수열 정렬 (2) | 2019.07.30 |
백준 15652번 N과 M (4) (0) | 2019.07.14 |
백준 15649번 N과 M (1) (0) | 2019.07.14 |
백준 1926번 그림 (0) | 2019.07.10 |