Algorithm/백준
C++ 알고리즘 - 백준 25501 재귀의 귀재 (참조자 문자열)
마루설아
2025. 1. 17. 21:49
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;
}
}