| ||||||||||
| 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 | |||||||||
求大神看看我的为什么会超时#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#define Max 0xfffff
#define INF 999999
using namespace std;
char s1[100],s2[100],s3[200],s[200],s0[200];
void Work()
{
int i,j,n,t=0;
scanf("%d",&n);
scanf("%s%s%s",s1,s2,s3);
strcpy(s,s1);
strcat(s,s2);
strcpy(s0,s);
while(1)
{
if(strcmp(s,s3)==0)
break;
t++;
for (j=0;j<n;j++) s1[j]=s[j];
for (i=0;i<n;i++,j++) s2[i]=s[j];
for (i=0,j=0;i<n;i++,j+=2)
{
s[j]=s2[i];
s[j+1]=s1[i];
}
if (strcmp(s0,s)==0) {t=-1;break;}
}
printf("%d\n",t);
}
int main()
{
int i,n1;
scanf("%d",&n1);
for (i=1;i<=n1;i++)
{
printf("%d ",i);
Work();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator