| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
什么DFA什么的~ 直接水过去了,忍不住贴段代码~~#include<iostream>
#include<cstring>
using namespace std;
char s[1100];
int len;
int tote,pose,totfu,totpoint,posp;
bool checkshu( int start0 , int tail0 , bool havepoint )
{
int i,start,pospoint;
start = start0;
if ( s[start]=='+' || s[start]=='-' ) start++;
pospoint = -1;
for (i=start; i<=tail0; i++)
{
if ( s[i]>='0' && s[i]<='9' )
{
}
else if ( s[i]=='.' )
{
pospoint = i;
if (!havepoint) return false;
}
else
return false;
}
if ( pospoint==start || pospoint==tail0 )
return false;
return true;
}
void work()
{
int i,start,tail;
len = strlen( s );
start=0;
while ( s[start]==' ' ) start++;
tail= len-1;
while ( s[tail]==' ' ) tail--;
tote=0; totfu=0; totpoint=0;
for (i=start; i<=tail; i++)
{
if ( s[i]>='0' && s[i]<='9' )
{
}
else if ( s[i]=='e' || s[i]=='E' )
{
tote++; pose=i;
}
else if ( s[i]=='+' || s[i]=='-' )
totfu++;
else if ( s[i]=='.' )
{
totpoint++;
}
else
{
cout<<"ILLEGAL"<<endl;
return;
}
}
if ( tote>1 || totfu>2 || totpoint>1)
{
cout<<"ILLEGAL"<<endl;
return;
}
if (tote>0)
{
if ( !checkshu( start , pose-1, totpoint ) )
{
cout<<"ILLEGAL"<<endl;
return;
}
if ( !checkshu( pose+1, tail, 0 ) )
{
cout<<"ILLEGAL"<<endl;
return;
}
}
else
{
if ( !checkshu( start , tail , totpoint ) )
{
cout<<"ILLEGAL"<<endl;
return;
}
}
cout<<"LEGAL"<<endl;
}
int main()
{
int t;
cin>>t;
while (t--)
{
//cin.getline( s , 1100 , '\n' );
cin>>s;
work();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator