Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大神看看我的为什么会超时

Posted by acm_lvy at 2014-10-30 10:40:41 on Problem 3087
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator