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

有什么要注意的啊??

Posted by dexter at 2004-03-22 22:53:06 on Problem 1537
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100
char str[MAX];
int deci_exp()
{
	int i;
	for(i=0;str[i];i++)
		if(str[i]=='.'||str[i]=='E'||str[i]=='e')
			return 1;
	return 0;
}
int one_on_side()
{
	int i;
	for(i=0;str[i];i++)
		if(str[i]=='.')
		{
			if(i==0||i==(int)strlen(str)-1)
				return 0;
			else if(isdigit(str[i-1])&&isdigit(str[i+1]))
				return 1;
			else
				return 0;
		}
	return 1;
}
int sign()
{
	int i,flag;
	flag=1;
	for(i=0;str[i]==' ';i++);
	if(str[i]=='+'||str[i]=='-')
		flag=1;
	for(i=0;str[i];i++)
			if(str[i]=='e'||str[i]=='E')
			{
				if(str[i+1]=='+'||str[i+1]=='-')
					flag=1;
			    else
					flag=0;
			}
	return flag;
}
int fraction()
{
	int i;
	for(i=0;str[i];)
		if(str[i]=='E'||str[i]=='e')
		{
			for(i++;str[i];i++)
				if(str[i]=='.')
					return 0;
		}
		else
			i++;
	return 1;
}
int be_e()
{
	int i;
	for(i=0;str[i];i++)
		if(str[i]=='e'||str[i]=='E')
			if((isdigit(str[i-1])&&isdigit(str[i+1]))||(isdigit(str[i-1])&&(str[i+1]=='+'||str[i+1]=='-')&&isdigit(str[i+2])))
				return 1;
			else
				return 0;
	return 1;
}
int space()
{
	int i,j,k;
	for(i=0;str[i]==' ';i++);
	j=i;
	for(j=strlen(str)-1;str[j]==' ';j--);
	k=j;
	for(i=j;i<=k;i++)
		if(str[i]==' ')
			return 0;
	return 1;
}
char* move()
{
	
	int i;
	for(i=0;str[i]==' ';i++);
	return str+i;
}
int cha()
{
	int i;
	for(i=0;str[i];i++)
		if(!(str[i]=='+'||str[i]=='-'||isdigit(str[i])||str[i]=='.'))
			return 0;
	return 1;
}
main()
{
	int flag;
	gets(str);
	while(strcmp("*",str))
	{
		flag=cha()&&deci_exp()&&one_on_side()&&sign()&&space()&&be_e()&&fraction();
		move();
		printf("%s ",move());
		if(flag)
			puts("is legal.");
		else
			puts("is illegal.");
		gets(str);
	}
}


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