标签:style blog io ar color sp for div log
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 char s1[110],s2[110],ss[220]; 5 int len,n; 6 7 int f() 8 { 9 int ans=0; 10 char t1[110],t2[110],tt[220]; 11 strcpy(t1,s1);strcpy(t2,s2); 12 while (1) 13 { 14 ans++; 15 for (int i=0;i<len;i++) 16 { 17 tt[i*2]=t2[i]; 18 tt[i*2+1]=t1[i]; 19 } 20 tt[2*len]=‘\0‘; 21 if (strcmp(tt,ss)==0) return ans; 22 for (int i=0;i<len;i++) 23 { 24 t1[i]=tt[i]; 25 t2[i]=tt[i+len]; 26 } 27 t1[len]=‘\0‘; 28 t2[len]=‘\0‘; 29 if (strcmp(t1,s1)==0 && strcmp(t2,s2)==0) break; 30 } 31 return -1; 32 } 33 34 int main() 35 { 36 scanf("%d",&n); 37 for (int t=1;t<=n;t++) 38 { 39 scanf("%d %s %s %s",&len,s1,s2,ss); 40 printf("%d %d\n",t,f()); 41 } 42 return 0; 43 }
标签:style blog io ar color sp for div log
原文地址:http://www.cnblogs.com/NicoleLam/p/4147613.html