https://www.acmicpc.net/problem/25501
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int cnt = 0;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int recursion(string& s, int l, int r) {
cnt++;
if (l >= r) return 1;
else if (s[l] != s[r]) return 0;
else return recursion(s, l + 1, r - 1);
}
int isPalindrome(string& s) {
return recursion(s, 0, s.size() - 1);
}
int main(void) {
CPP_INIT();
int input;
string str;
cin >> input;
for (int i = 0; i < input; i++) {
cin >> str;
cout << isPalindrome(str) << " ";
cout << cnt << endl;
cnt = 0;
}
}
'Algorithm > 백준' 카테고리의 다른 글
C++ 알고리즘 - 백준 4375 1 (모듈러 연산 원칙 관련) (0) | 2025.01.19 |
---|---|
C++ 알고리즘 - 백준 24060 알고리즘 수업 - 병합 정렬 1 (0) | 2025.01.17 |
C++ 알고리즘 - 백준 10870 피보나치 수 5 (0) | 2025.01.17 |
C++ 알고리즘 - 백준 11729 하노이 탑 이동순서 (재귀함수) (0) | 2025.01.17 |
C++ 알고리즘 - 백준 20920 영단어 암기는 괴로워 (맵, 벡터) (0) | 2025.01.17 |