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

为什么WA了啊 !!!!!!!!!!!!!!

Posted by leiwen at 2009-08-07 10:23:24 on Problem 1056
#include<iostream>
#include<string.h>
using namespace std;
struct node
{
	char a[20];
	int len;
}p[100];
int cmp(const void *a,const void *b) 
{ 
	return(*(node *)a).len>(*(node *)b).len?1:-1; 
}
int main()
{
	int i,j,flag,count=1;
	char a[100];
	while(cin>>p[0].a)
	{
		flag=0;
		if(strcmp(p[0].a,"9")==0)
		{
			cout<<"Set "<<count++<<" is immediately decodable"<<endl;
			continue;
		}
		p[0].len=strlen(p[0].a);
		for(i=1;;i++)
		{
			cin>>p[i].a;
			if(p[i].a[0]=='9')
				break;
			p[i].len=strlen(p[i].a);
		}
		qsort(p,i,sizeof(p[0]),cmp);
		for(j=0;j<i;j++)
		{
			strcpy(a,p[j+1].a);
			a[p[j].len]='\0';
			if(strcmp(a,p[j].a)==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
			cout<<"Set "<<count<<" is immediately decodable"<<endl;
		else
			if(flag==1) 
				cout<<"Set "<<count<<" is not immediately decodable"<<endl;
		count++;
	}
	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