Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:不知道自己用了什么算法,反正做出来了.......In Reply To:数据都过了,但是为什么就是WA啊。求大神教教小弟。十分感谢啊。以下附代码。 Posted by:mm353395330 at 2012-11-27 21:26:00 #include "iostream" #include "string.h" #include "stdio.h" #define MAX 1000 using namespace std; int main() { int Round,C; char str1[MAX],str2[MAX],str[2*MAX] ,str12[2*MAX],B_str12[2*MAX]; scanf("%d",&Round); for(int I=0;I<Round;I++) { int flag=0; scanf("%d",&C); for(int i=0;i<C;i++) { cin>>str1[i]; str1[i+1]='\0'; } for(int i=0;i<C;i++) { cin>>str2[i]; str2[i+1]='\0'; } for(int i=0;i<2*C;i++) { cin>>str[i]; str[i+1]='\0'; } for(int i=0,j1=0,j2=0;i<2*C;i++) { if(i%2==0) { str12[i]=str2[j2++]; str12[i+1]='\0'; } else { str12[i]=str1[j1++]; str12[i+1]='\0'; } } strcpy(B_str12,str12); flag++; while(strcmp(str12,str)) { for(int i=0;i<C;i++) { str1[i]=str12[i]; str1[i+1]='\0'; } for(int i=C,j=0;i<2*C;i++) { str2[j++]=str12[i]; str2[j]='\0'; } for(int i=0,j1=0,j2=0;i<2*C;i++) { if(i%2==0) { str12[i]=str2[j2++]; str12[i+1]='\0'; } else { str12[i]=str1[j1++]; str12[i+1]='\0'; } } if( !strcmp(str12,B_str12) ) { flag=-1; break; } flag++; } cout<<I+1<<' '<<flag<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator