기타/백준일지
[백준] 17609번 회문
민지기il
2025. 4. 13. 22:54
#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
using namespace std;
int T;
vector<string> V;
void Input(){
cin>>T;
for(int i=0;i<T;i++){
string S; cin>>S;
V.push_back(S);
}
}
int palindrome(int left, int right, int deleted, string str){
while(left<right){
if(str[left]!=str[right]){
if(deleted==0){
if(palindrome(left+1, right, 1,str)==0 || palindrome(left, right-1, 1, str)==0)
return 1;
return 2;
}
else return 2;
}
else{
left++;
right--;
}
}
return 0;
}
int main(){
fastio;
Input();
for(int t=0; t<T; t++){
string str=V[t];
int result = palindrome(0, str.length()-1, 0, str);
cout<<result<<'\n';
}
return 0;
}
[참고]
https://yabmoons.tistory.com/704