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

大神请指导一下,为什么总是超时,不管是C++还是G++!!!跪求速解!!!

Posted by harden at 2016-06-27 16:09:21 on Problem 1035
小生代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#define M 10010
#define N 15
using namespace std;
char ch[M][N],s[N];
int a[M];
int search(char *a,char *b)
{
	int lena=strlen(a);
	int lenb=strlen(b);
	if(lena==lenb)
	{
		int flag=0;
		for(int i=0;i<lena;i++)
		  if(a[i]!=b[i])
		    if(!flag) flag=1;
			else return 0;
		if(flag==1)return 1;
	}
	if(lena==lenb+1)
	{
		int pa=0,pb=0,flag=0;
		while(1)
		{
			if(pa>=lena&&pb>=lenb)break;
			if(a[pa]==b[pb])
			{
				pa++;
				pb++;
			}
			else
			  if(!flag)
			  {
			  	flag=1;
			  	pa++;
			  }
			  else return 0;
		}
		if(flag==1)return 1;
	}
	if(lena==lenb-1)
	{
		int pa=0,pb=0,flag=0;
		while(1)
		{
			if(pa>=lena&&pb>=lenb)break;
			if(a[pa]==b[pb])
			{
				pa++;
				pb++;
			}
			else
			  if(!flag)
			  {
			  	flag=1;
			  	pb++;
			  }
			  else return 0;
		}
		if(flag==1)return 1;
	}
	return 0;
}
int main()
{
	int n=0;
	while(1)
	{
		scanf("%s",ch[++n]);
		if(ch[n][0]=='#')
		{
			n--;
			break;
		}
	}
	while(1)
	{
		int flag=0,cnt=0;
		scanf("%s",s);
		if(s[0]=='#')break;
		printf("%s",s);
		for(int i=1;i<=n;i++)
		{
			if(strcmp(s,ch[i])==0)
			{
				printf(" is correct\n");
				flag=1;
				break;
			}
			else if(search(s,ch[i]))
			  a[++cnt]=i;
		}
		if(!flag)
		{
			printf(":");
			for(int i=1;i<=cnt;i++)
			  printf(" %s",ch[a[i]]);
			printf("\n");
		}
	}
	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