rt,题目link
代码
#include<bits/stdc++.h>
using namespace std;
bool c[11];
int n,m;
void f(int t){
bool flag=true;
if(n==1){
cout<<"Move the "<<m<<"th ring ";
if(c[1]==0)cout<<"up"<<endl;
else cout<<"down"<<endl;
}
for(int i=1;i<n-1;i++){
if(c[i]==1)flag=0;
}
if(c[t-1]==0)flag=0;
if(flag){
c[t]=!c[t];
cout<<"Move the "<<t+m<<"th ring ";
if(c[t]==1)cout<<"up"<<endl;
else cout<<"down"<<endl;
f(t-2);
f(t-1);
}
}
int main(){
memset(c,1,sizeof(c));
int a;
cin>>a;
cin>>n>>m;
n-=m;
cout<<"Start moving!"<<endl;
f(n);
cout<<"End moving!"<<endl;
return 0;
}