2480980_ac_0ms_120k.cpp

来自「北大大牛代码 1240道题的原代码 超级权威」· C++ 代码 · 共 78 行

CPP
78 行
字号
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
	int t, i;
	char str[1001];

	scanf("%d",&t);
	while(t--)
	{
		scanf("%s",str);
		if(str[0]=='+'||str[0]=='-')
			strcpy(str,&str[1]);
		i = 0;
		while(str[i]!='\0'&&isdigit(str[i]))
			i++;
		if(i==0)
		{
			printf("ILLEGAL\n");
			continue;
		}
		if(str[i]=='\0')
		{
			printf("LEGAL\n");
			continue;
		}
		if(str[i]=='.')
		{
			strcpy(str,&str[i+1]);
			i = 0;
			while(str[i]!='\0'&&isdigit(str[i]))
				i++;
			if(i==0)
			{
				printf("ILLEGAL\n");
				continue;
			}
			if(str[i]=='\0')
			{
				printf("LEGAL\n");
				continue;
			}
			if(str[i]=='e'||str[i]=='E')
			{
				strcpy(str,&str[i+1]);
				goto E;
			}
			printf("ILLEGAL\n");
			continue;
		}
		if(str[i]=='e'||str[i]=='E')
		{
			strcpy(str,&str[i+1]);
E:
			if(str[0]=='+'||str[0]=='-')
				strcpy(str,&str[1]);
			i = 0;
			while(str[i]!='\0'&&isdigit(str[i]))
				i++;
			if(i==0)
			{
				printf("ILLEGAL\n");
				continue;
			}
			if(str[i]=='\0')
			{
				printf("LEGAL\n");
				continue;
			}
			printf("ILLEGAL\n");
			continue;
		}
		printf("ILLEGAL\n");
		continue;
	}
	return 1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?