#include <bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<"="<<x<<endl
using ll = long long;
int x;
string s;
int hanoi(int n,char a,char b,char c){
if (n==1){
if (s[0]==a || s[0]==b){
return 1;
}
return 0;
}
else{
if (s[n-1]==a){
return hanoi(n-1,a,c,b);
}
if (s[n-1]==b){
return hanoi(n-1,c,b,a);
}
return 0;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>x>>s;
if (hanoi(x,'A','B','C')){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
return 0;
}
// don't waste time!!!
本人测试样例
3
ACB
(去掉 freopen),dev c++ 没有反应,return 0 都没有,还要再输入好多行才可以程序结束。但是在 CF 上提交 AC 了。这是我 dev c++ 抽风了吗?如果是的,怎么解决?