However, I did not see any cases of the form:
Maybe that's your problem?1.2e1.2
Moderator: Board moderators
I've try all the cases above on my codes,and it can work out all of the them.Why I still got WA? I've got about 7 WA on this problem,I'm so frustrated,I really need some one help me!My accepted solution gives this output on these tests:
Input:
1E1
1e1
1E
1EE1
1 E1
.1E1
1E.1
1E1.1
++1E1
1E--1
1.1.1E1
abcd
1
1.1
0e-0
*
Output:
1E1 is legal.
1e1 is legal.
1E is illegal.
1EE1 is illegal.
1 E1 is illegal.
.1E1 is illegal.
1E.1 is illegal.
1E1.1 is illegal.
++1E1 is illegal.
1E--1 is illegal.
1.1.1E1 is illegal.
abcd is illegal.
1 is illegal.
1.1 is legal.
0e-0 is legal.
Hope it helps
Jorge Pinto
Code: Select all
#include<iostream.h>
int main(void)
{
char d[10000];
int i,front,back,islegal,eCount,dotCount,exp,dot;
while(1)
{
for(i=0;i<300;i++)d[i]=' ';
exp=300;
dot=300;
islegal=1;
eCount=0;
dotCount=0;
cin.getline(d,100,'\n');
if(d[0]=='*')break;
for(i=0;d[i]==32;i++);
front=i;
for(i=299;d[i]==32||d[i]==0;i--);
back=i;//cout<<back<<endl;
//for(i=front;i<=back;i++)cout<<d[i];cout<<endl;
for(i=front;i<=back;i++)
{
if((d[i]<48||d[i]>57)&&(d[i]!='+')&&(d[i]!='-')&&(d[i]!='e')&&(d[i]!='E')&&(d[i]!='.'))
{
islegal=0;//cout<<"1111111111"<<endl;
break;
}
/*if(d[i]==32)
{
islegal=0;
break;
}*/
if(d[i]=='e'||d[i]=='E')
{
eCount++;
if(eCount>1)
{
islegal=0;//cout<<"222222222222"<<endl;
break;
}
exp=i;
if(d[exp-1]<48||d[exp-1]>57)
{
islegal=0;//cout<<"33333333333"<<endl;
break;
}
//if((d[exp+1]!='+'&&d[exp+1]!='-')||(d[exp+2]<=48||d[exp+2]>57))
if(d[exp+1]!='+'&&d[exp+1]!='-')
{
if((d[exp+1]<48||d[exp+1]>57)||((d[exp+1]=='0')&&(d[exp+2]!=' '&&d[exp+2]!=0)))
{
islegal=0;//cout<<"444444444444"<<endl;
break;
}
}
if(d[exp+1]=='+'||d[exp+1]=='-')
{
if(d[exp+2]<48||d[exp+2]>57)
{
islegal=0;//cout<<"xxxxxxxxxxxxxx"<<endl;
break;
}
/*if(d[exp+2]==0||d[exp+2]==' ')
{
islegal=0;cout<<"yyyyyyyyyyyyy"<<endl;
break;
}*/
}
}
if(d[i]=='.')
{
dotCount++;
dot=i;
if(dotCount>1)
{
islegal=0;//cout<<"555555555555"<<endl;
break;
}
if(i>exp)
{
islegal=0;//cout<<"6666666666"<<endl;
break;
}
if((d[dot+1]<48||d[dot+1]>57)||(d[i-1]<48||d[dot-1]>57))
{
islegal=0;//cout<<"7777777777"<<endl;
break;
}
}
if(d[i]=='+'||d[i]=='-')
{
if(i!=front&&i!=exp+1)
{
islegal=0;//cout<<"88888888888888"<<endl;
break;
}
}
}
if(exp==300&&dot==300)islegal=0;//cout<<"!!!!!!!!!"<<endl;}
if(islegal==0)
{
for(;front<=back;front++)cout<<d[front];
cout<<" is illegal."<<endl;
continue;
}
if((d[front]=='+'||d[front]=='-')&&d[front+1]==48)
{
if((d[front+2]!='.')&&(d[front+2]!='e')&&(d[front+2]!='E'))
{
islegal=0;//cout<<"99999999999"<<endl;
}
}
else if(d[front]==48)
{
if((d[front+1]!='.')&&(d[front+1]!='e')&&(d[front+1]!='E'))
{
islegal=0;//cout<<"1010101010101"<<endl;
}
}
if(islegal==0)
{
for(;front<=back;front++)cout<<d[front];
cout<<" is illegal."<<endl;
continue;
}
if(islegal==1)
{
for(;front<=back;front++)cout<<d[front];
cout<<" is legal."<<endl;
}
}
return(0);
}
Code: Select all
Code removed!
Code: Select all
code removed
Code: Select all
457693476987495864364.5645634564564356e4563564564356543
457693476987495864364.5645634564564356e+4563564564356543
457693476987495864364.5645634564564356e-4563564564356543
+457693476987495864364.5645634564564356e4563564564356543
-457693476987495864364.5645634564564356e4563564564356543
457693476987495864364.+5645634564564356e4563564564356543
457693476987495864364.-5645634564564356e4563564564356543
*
Code: Select all
457693476987495864364.5645634564564356e4563564564356543 is legal.
457693476987495864364.5645634564564356e+4563564564356543 is legal.
457693476987495864364.5645634564564356e-4563564564356543 is legal.
+457693476987495864364.5645634564564356e4563564564356543 is legal.
-457693476987495864364.5645634564564356e4563564564356543 is legal.
457693476987495864364.+5645634564564356e4563564564356543 is illegal.
457693476987495864364.-5645634564564356e4563564564356543 is illegal.
Code: Select all
457693476987495864364.5645634564564356e4563564564356543 is illegal.
457693476987495864364.5645634564564356e+4563564564356543 is illegal.
457693476987495864364.5645634564564356e-4563564564356543 is illegal.
+457693476987495864364.5645634564564356e4563564564356543 is illegal.
-457693476987495864364.5645634564564356e4563564564356543 is illegal.
457693476987495864364.+5645634564564356e4563564564356543 is illegal.
457693476987495864364.-5645634564564356e4563564564356543 is illegal.
* is illegal.
Code: Select all
#include<stdio.h>
#include<string.h>
char line[10000];
int main(){
int i,flag;
while(scanf("%s",line)==1){
if(line[0]=='*')break;
flag=0;
for(i=0;line[i];i++){
if(line[i]>='0' && line[i]<='9'){flag=3;}
else {flag=0;break;}
}
if(flag==3){printf("%s is illegal.\n",line);continue;}
for(i=0;line[i];i++){
if(line[i]=='.' && ((line[i+1]<='0' && line[i+1]>='9')|| line[i+1]==NULL) ){
printf("%s is illegal.\n",line);flag=1;break;
}
else if(line[0]=='e' || line[0]=='E'){
printf("%s is illegal.\n",line);flag=1;break;
}
else if((line[i]=='e' || line[i]=='E') && (line[i+1]==NULL)){
printf("%s is illegal.\n",line);flag=1;break;
}
else if(line[i]=='e' || line[i]=='E'){
for(i;line[i];i++){
if(line[i]=='.'){
printf("%s is illegal.\n",line);flag=1;break;
}
}
}
}
if(flag!=1)printf("%s is legal.\n",line);
}
return 0;
}
Code: Select all
test