Monday 4 May 2009

POJ 3332


这题完全应该用 java + regex 做的。
#include <iostream>
#include <cctype>
using namespace std;
bool ok(char* x){
if(*x=='+'||*x=='-')
if (!isdigit(*++x)) return false;
if(!isdigit(*x)) return false;
for(;isdigit(*x);++x);
if (*x==0) return true;
else if (*x=='.') {
if (!isdigit(*++x)) return false;
for(;isdigit(*x);++x);
}
if (*x=='e'||*x=='E') {
++x;
if (*x=='+'||*x=='-') ++x;
if(!isdigit(*x)) return false;
for(;isdigit(*x);++x);
}
return *x==0;
}
int main() {
int n; char x[1024];
for(cin>>n;n--;cout<<(ok(x)?"LEGAL":"ILLEGAL")<<endl)cin>>x;
return 0;
}

No comments:

Post a Comment