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

哪位牛人帮忙给组BT的数据?

Posted by a024014 at 2007-04-14 14:13:08 on Problem 2475
#include <stdio.h>
#include <string.h>
bool judge(char *str,int start,int end)
{
	int i,j,pos,px;
	char s[256];
	bool flag=false;
	if(str[start]!='{'||str[end-1]!='}') return false;
	if(end-start==2||end-start==3) return true;
	pos=start+1;
	while(1)
	{
		if(pos>=end-1)
			break;
		if(str[pos]=='{')
		{
			for(i=pos+1;i<end-1;i++)
			{
				if(str[i]=='}')
				{
					if(i==end-2&&judge(str,pos,i+1))
						return true;
					else if(i!=end-2&&str[i+1]==',')
						if(judge(str,pos,i+1))
						{
							s[0]='{',px=1;
							for(j=i+2;j<end-1;j++)
								s[px++]=str[j];
							s[px]='}';
							s[px+1]='\0';
							if(judge(s,0,strlen(s)))
								return true;
						}
				}
			}
		}
		flag=false;
		if(pos+1>=end-1)
			break;
		if(str[pos+1]!=',') return false;
		else flag=true;
		pos=pos+2;
	}
	if(flag) return false;
	return true;
}
int main()
{
	int t,c=0;
	char str[256];
	//freopen("d:\\1.txt","r",stdin);
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s",str);
		printf("Word #%d: ",++c);
		judge(str,0,strlen(str))?printf("Set\n"):printf("No Set\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