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 coobj2008 at 2011-08-30 18:30:48 on Problem 2138
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

struct node
{
	char s[100];
	int len;
	int g;
}e[1005];
bool cmp(const node &a,const node &b)
{
	if(a.len!=b.len) return a.len<b.len;
	else return strcmp(a.s,b.s)>0?false:true;
}
int main()
{
	int i,j,k,m,n,d,flag,ans,temp;
	char str[100];
	scanf("%d %s",&d,str);
	for(i=0;i<d;i++)
	{
		scanf("%s",e[i].s);
		e[i].len=strlen(e[i].s);
		e[i].g=0;
	}
	sort(e,e+d,cmp);
	for(i=0;i<d;i++)
		if(strcmp(str,e[i].s)==0)
		{
			e[i].g=1;
			break;
		}
	for(j=i;j<d;j++)
		for(k=j+1;k<d;k++)
		{
			flag=1;
			m=n=0;
			int cc=0;
			if(e[j].len+1==e[k].len)
			{
				while(e[j].s[m]&&e[k].s[n])
				{
					if(e[j].s[m]!=e[k].s[n])
					{
						if(cc==0) 
						{
							cc++;
							m--;
						}
						else
						{
							flag=0;
							break;
						}							
					}
					m++;
					n++;
				}
			}
			else flag=0;
			if(flag) e[k].g=e[j].g+1;
		}
	ans=0;
	for(i=0;i<d;i++)
		if(ans<e[i].g) 
		{
			ans=e[i].g;
			temp=i;
		}
	printf("%s\n",e[temp].s);
	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