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

why wa?

Posted by iShowFun at 2009-02-22 21:09:36 on Problem 1056
#include<string>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define Max 1000
using namespace std;

typedef struct
{
	string c;
	int l;
}stcode;
stcode code[Max];
int icount;
int test;
bool avail;
bool cmp(stcode a,stcode b)
{
	return a.l<b.l;
}
int main()
{
	icount=test=0;
	avail=true;
	char strin[200];
	string str;
	int i,j;
	while(EOF!=scanf("%s",strin))
	{
		str=strin;
		if(str=="9")
		{
			sort(code,code+icount,cmp);
			for(i=0;i<icount;i++)
			{
				for(j=i+1;j<icount;j++)
				{
					if(code[i].c==code[j].c.substr(0,code[i].l))
					{
						avail=false;
						goto endit;
					}
				}
			}
endit:			test++;
			cout<<"Set "<<test<<" is ";			
			if(!avail)
				cout<<"not ";
			cout<<"immediately decodable"<<endl;
			icount=0;
			continue;
		}
		else
		{
			code[icount].c=str;
			code[icount].l=str.size();
			icount++;
		}
	}
	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