언어 : cpp
방법 :
받은 스트링 순차적으로 비교하면 된다~
단, 대소문자 구분없으므로 대문자로 치환하거나 소문자로 치환해서 비교할 것
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool isPalindrome(string str)
{
int n, q;
n = str.length();
q = n / 2;
for(int i = 0 ; i <q ; i++)
{
if (toupper(str[n-1]) == toupper(str[i]))
{
n -= 1;
}
else
{
return false;
}
}
return true;
}
int main()
{
int cnt = 0;
string str;
cin >> cnt ;
cin.ignore();
for (int i = 0; i < cnt; i++)
{
getline(cin, str);
if (true == isPalindrome(str))
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}
'Programming > 알고리즘' 카테고리의 다른 글
[프로그래머스] 타겟 넘버 (0) | 2021.03.22 |
---|---|
[프로그래머스] 크레인 인형뽑기 게임 (0) | 2021.03.16 |
[백준][2577] 숫자의 개수 (0) | 2020.10.17 |
백준 3190 뱀 (0) | 2019.10.11 |
정렬 알고리즘 - 수정 (0) | 2017.11.17 |