P092 问题肯定处在我的test函数里面,单独用后两行可以过样例 求各位dalao指导 可以让全机房同学关注dalao(大概5人....)
#include<bits/stdc++.h>
using namespace std;
bool use[28];
int n,a[28];
string x,y,z;
bool test(){
for(int i=0;i<n;i++){
int q,w,e;
q=a[x[i]-'A'+1];
w=a[y[i]-'A'+1];
e=a[z[i]-'A'+1];
if((q+w+1)%n==e||(q+w)%n==e){
return true;
}
}
return false;
}
void dfs(int now){
if(now==n+1){
if(test()){
for(int j=1;j<=n;j++){
cout<<a[j]<<' ';
}
exit(0);
}
return;
}
for(int i=0;i<n;i++){
if(!use[i]){
a[now]=i;
use[i]=true;
dfs(now+1);
use[i]=false;
}
}
return;
}
void work(){
cin>>n;
scanf("%s",&x);
scanf("%s",&y);
scanf("%s",&z);
dfs(1);
}
int main(){
work();
}