#include <bits/stdc++.h>
using namespace std;
int main(){
int flag;
string input, ans;
while(getline(cin, input)){
if(input == "*")break;
int szz = input.size(), dot = 0, dot_f = 0, exp = 0, exp_f = 0, invalid = 0, sp = 0, an = 0, sign = 0;
for(int i = 0; i < szz; i++){
if(input[i] == 32 && !sp)continue;
else{
ans.push_back(input[i]);
sp = 1;
}
}
int sz1 = ans.size();
for(int i = sz1-1; i >= 0; i--){
if(ans[i] == 32)an++;
else break;
}
for(int i = 0; i < an; i++)ans.erase(ans.size()-1);
int sz = ans.size();
for(int i = 0; i < sz; i++){
if((ans[i] >= '0' && ans[i] <= '9') || ans[i] == 'e' || ans[i] == 'E' || ans[i] == '.' || ans[i] == '+' || ans[i] == '-'){
if(ans[i] == '.'){
if(i == 0)invalid = 1;
if(exp)invalid = 1;
dot += 1;
if((i != sz-1) && (ans[i+1] >= 48 && ans[i+1] <= 57))dot_f = 1;
}
if(ans[i] == 'e' || ans[i] == 'E'){
if(i == 0)invalid = 1;
exp += 1;
if((i != sz-1) && (ans[i+1] >= '0' && ans[i+1] <= '9'))exp_f = 1;
else if(ans[i+1] == '-' || ans[i+1] == '+'){
if((i+1 != sz-1) && (ans[i+2] >= '0' && ans[i+2] <= '9'))exp_f = 1;
}
}
if(ans[i] == '-' || ans[i] == '+'){
if(i == 0 || ans[i-1] == 'e' || ans[i-1] == 'E')sign = 0;
else sign = 1;
}
}
else invalid = 1;
}
if(invalid || sign)cout << ans << " is illegal." << endl;
else if(dot == 1 && dot_f == 1 && exp == 1 && exp_f == 1)cout << ans << " is legal." << endl;
else if(dot == 1 && dot_f == 1 && exp == 0 && exp_f == 0)cout << ans << " is legal." << endl;
else if(dot == 0 && dot_f == 0 && exp == 1 && exp_f == 1)cout << ans << " is legal." << endl;
else cout << ans << " is illegal." << endl;
ans.clear();
}
return 0;
}
using namespace std;
int main(){
int flag;
string input, ans;
while(getline(cin, input)){
if(input == "*")break;
int szz = input.size(), dot = 0, dot_f = 0, exp = 0, exp_f = 0, invalid = 0, sp = 0, an = 0, sign = 0;
for(int i = 0; i < szz; i++){
if(input[i] == 32 && !sp)continue;
else{
ans.push_back(input[i]);
sp = 1;
}
}
int sz1 = ans.size();
for(int i = sz1-1; i >= 0; i--){
if(ans[i] == 32)an++;
else break;
}
for(int i = 0; i < an; i++)ans.erase(ans.size()-1);
int sz = ans.size();
for(int i = 0; i < sz; i++){
if((ans[i] >= '0' && ans[i] <= '9') || ans[i] == 'e' || ans[i] == 'E' || ans[i] == '.' || ans[i] == '+' || ans[i] == '-'){
if(ans[i] == '.'){
if(i == 0)invalid = 1;
if(exp)invalid = 1;
dot += 1;
if((i != sz-1) && (ans[i+1] >= 48 && ans[i+1] <= 57))dot_f = 1;
}
if(ans[i] == 'e' || ans[i] == 'E'){
if(i == 0)invalid = 1;
exp += 1;
if((i != sz-1) && (ans[i+1] >= '0' && ans[i+1] <= '9'))exp_f = 1;
else if(ans[i+1] == '-' || ans[i+1] == '+'){
if((i+1 != sz-1) && (ans[i+2] >= '0' && ans[i+2] <= '9'))exp_f = 1;
}
}
if(ans[i] == '-' || ans[i] == '+'){
if(i == 0 || ans[i-1] == 'e' || ans[i-1] == 'E')sign = 0;
else sign = 1;
}
}
else invalid = 1;
}
if(invalid || sign)cout << ans << " is illegal." << endl;
else if(dot == 1 && dot_f == 1 && exp == 1 && exp_f == 1)cout << ans << " is legal." << endl;
else if(dot == 1 && dot_f == 1 && exp == 0 && exp_f == 0)cout << ans << " is legal." << endl;
else if(dot == 0 && dot_f == 0 && exp == 1 && exp_f == 1)cout << ans << " is legal." << endl;
else cout << ans << " is illegal." << endl;
ans.clear();
}
return 0;
}
No comments:
Post a Comment