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了的DFA做法呵呵。。。。

Posted by hanjialong at 2008-09-09 19:19:27 on Problem 3332
#include<iostream>
#include<ctype.h>
using namespace std;

const int error=9;

int f(int s,char input)
{
	switch(s)
	{
	case 0:
		{
			if(isdigit(input)) return 2;
			if(input=='+'||input=='-') return 1;
			if(input=='\0') return 8;
			break;
		}
	case 1:
		{
			if(isdigit(input)) return 2;
			break;
		}
	case 2:
		{
			if(isdigit(input)) return 2;
			if(input=='.') return 3;
			if(input=='e'||input=='E') return 5;
			if(input=='\0') return 8;
			break;
		}
	case 3:
		{
			if(isdigit(input)) return 4;
			break;
		}
	case 4:
		{
			if(isdigit(input)) return 4;
			if(input=='e'||input=='E') return 5;
			if(input=='\0') return 8;
			break;
		}
	case 5:
		{
			if(isdigit(input)) return 7;
			if(input=='+'||input=='-') return 6;
			break;
		}
	case 6:
		{
			if(isdigit(input)) return 7;
			break;
		}
	case 7:
		{
			if(isdigit(input)) return 7;
			if(input=='\0') return 8;
			break;
		}
	}
	return error;
}
char *p;

char get()
{
	p++;
	return *(p-1);
}

int main()
{
	const int maxn=1100;
	char a[maxn];
	int s,t;
	scanf("%d\n",&t);
	while(t--)
	{
		cin.getline(a,maxn);
		for(p=a;*p;p++);
		for(;p>=a&&*(p-1)==' ';p--);
		*p='\0';
		for(p=a;*p==' ';p++);
		s=0;
		while((s=f(s,get()))!=8&&s!=error);
		if(s==8) printf("LEGAL\n");
		else printf("ILLEGAL\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