10174 펠린드롬
2019. 8. 3. 12:20ㆍ알고리즘/백준
c++은 cin.ignore로 버퍼를 비워야 한다
문제: https://www.acmicpc.net/problem/10174
깃허브주소: https://github.com/surinoel/boj/blob/master/10174.cpp
This file contains 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 <string> | |
#include <sstream> | |
#include <iostream> | |
using namespace std; | |
char change_alpha(char c) { | |
if (c >= 'a' && c <= 'z') { | |
c -= 32; | |
} | |
return c; | |
} | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
cin.ignore(); | |
for (int i = 0; i < n; i++) { | |
string s; | |
getline(cin, s); | |
bool ok = true; | |
int left = 0, right = s.length() - 1; | |
while (left <= right) { | |
if (s[left] == ' ' || s[right] == ' ') { | |
if (s[left] != s[right]) { | |
ok = false; | |
} | |
} | |
else { | |
char a = change_alpha(s[left]); | |
char b = change_alpha(s[right]); | |
if (a != b) { | |
ok = false; | |
} | |
} | |
left++; | |
right--; | |
} | |
if (ok) cout << "Yes\n"; | |
else cout << "No\n"; | |
} | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
1188 음식 평론가 (0) | 2019.08.05 |
---|---|
3023 마술사 이민혁 (0) | 2019.08.04 |
1138 한 줄로 서기 (0) | 2019.08.02 |
1236 성 지키기 (0) | 2019.08.01 |
1543 문서 검색 (0) | 2019.08.01 |