https://www.acmicpc.net/problem/10988
#include <bits/stdc++.h>
using namespace std;
string word;
int cnt;
int main(){
cin >> word;
for (int i = 0 ; i < word.length()/2; i++) {
if (word[i] == word[word.length() - i -1]) {
cnt++;
}
}
if (cnt == word.length()/2) cout << 1;
else cout << 0;
return 0;
}
다시 알고리즘 문제 매일 풀기 도전.
지난 번에 python으로 풀어봤던 건데, C++로 다시 하려니 조금 막혔다.
단어 입력 받고, 단어 길이의 절반을 기준으로 대칭되는 부분을 비교한 뒤 일치하는지 카운트. 카운트가 (단어 길이/2)와 같으면 팰린드롬이다.
#include <bits/stdc++.h>
using namespace std;
string s, temp;
int main(){
cin >> s;
temp = s;
reverse(temp.begin(), temp.end());
if (temp == s) cout << 1 << "\n";
else cout << 0 >> "\n";
return 0;
}