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

果断暴力,不解释!(附暴力AC Code)

Posted by luchenqun at 2010-10-26 15:24:25 on Problem 1056
#include<iostream>
#include<string>
#include<algorithm>
#define MAX 10000
using namespace std;

struct A
{
	string str;
	int len;
}a[MAX];

int cmp(const void *a,const void *b)
{
	return ((struct A *)a)->len - ((struct A *)b)->len;
}

int main()
{
	string str[MAX],s;
	int Case=1,i=0,j,n;
	bool flag;
	while(cin>>a[i].str)
	{
		if(a[i].str=="9")
			goto begin;//谁说不能goto?
		else
		{
			a[i].len=a[i].str.size();
			i++;
			continue;
		}
begin:	n=i;
		flag=true;
		qsort(a,n,sizeof(a[0]),cmp);
		for(i=0;i<n;i++)
		{
			for(j=i+1;j<n;j++)
			{
				string temp(a[j].str,0,a[i].len);
					if(a[i].str==temp)
					{
						flag=false;
						i=MAX+8;
					}
			}
		}
		if(flag)
			cout<<"Set "<<Case++<<" is immediately decodable\n";
		else
			cout<<"Set "<<Case++<<" is not immediately decodable\n";
		i=0;
	}
	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