325 - Identifying Legal Pascal Real Constants

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

That I/O is correct.

However, I did not see any cases of the form:
1.2e1.2
Maybe that's your problem?

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

Cases like 1.2E1.2 have been tested. That was not the problem.

The first mistake was to ignore empty lines which I corrected thanks
to UFP2161.

That left one very stupid error. I didn't test something like
12345.-12345, i.e. a sign immediately following a decimal point.

Thanks to JUNBIN I found that too.

That shows that I'm still too careless with my test data.

Thanks a lot.

janrenfairy
New poster
Posts: 2
Joined: Sat Jul 03, 2004 9:26 pm
Location: China

Help me with 325,please!!!

Post by janrenfairy »

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
I've try all the cases above on my codes,and it can work out all of the them.Why I still got WA? :cry: I've got about 7 WA on this problem,I'm so frustrated,I really need some one help me!
Can any body who has got AC test your case on my codes maybe which I haven't considered,and tell me.Thanks a lot!
Here is my code:

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);
}


superyoga
New poster
Posts: 3
Joined: Sat Oct 09, 2004 2:51 pm

I need HELP!!!! - 325 Problem

Post by superyoga »

I need more input to test my program. I've tried some inputs that I've got from this forum, but the output are all correct!
Please, HELP ME!!!

Thanks

I'll put the input and output generated by my program. If you wanna see my program, I can post here... I've changed spaces into #.
Sorry my poor english.

[b]input:[/b]
[code]
1.2
###1.
##1.0e-55
##e-12
####6.5E
#####1e-12
##+4.1234567890E-99999
###7.6e+12.5
99

1E1
1e1
1E
1EE1
1#E1
.1E1
1E.1
1E1.1
++1E1
1E--1
1.1.1E1
abcd
1
1.1
0e-0
123.456+789
1e+
.1111
123.0e12.
123.0e12+
123.0e12-
EEEEEE
+++++++
.......
99###############
#########################################
++1E1
1E--1
6.2.
-.5
6..2
1.1.1E11
-75-
1E.1
.1E1
1E
1EE1
1.1.1E1
###7.6e+12.5
############1E1.1
+1.5e-1##2
+6-4.2
-75E-
-75E2-
-3.3e-9999999999999999999999999
#
1.1E1
###1.0e-55
##+4.1234567890E-99999
1.2
1
###1.
123.e123123123123123123+123123123123123123123
0e-0
.1E1
-e-12
-1e-12
1E1
1e1
5e6
5.2#####7
abcd
########################1.2########################1.2
123-E12
123.0e12E
5#e*6

5#e#6
1#E1
####6.5E
#e-12
####1e-12
########################1.2

*
[/code]


[b]output:[/b]
[code]
1.2 is legal.
###1. is illegal.
##1.0e-55 is illegal.
##e-12 is illegal.
####6.5E is illegal.
#####1e-12 is illegal.
##+4.1234567890E-99999 is illegal.
###7.6e+12.5 is illegal.
99 is illegal.
is illegal.
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.
123.456+789 is illegal.
1e+ is legal.
.1111 is illegal.
123.0e12. is illegal.
123.0e12+ is illegal.
123.0e12- is illegal.
EEEEEE is illegal.
+++++++ is illegal.
....... is illegal.
99############### is illegal.
######################################### is illegal.
++1E1 is illegal.
1E--1 is illegal.
6.2. is illegal.
-.5 is legal.
6..2 is illegal.
1.1.1E11 is illegal.
-75- is illegal.
1E.1 is illegal.
.1E1 is illegal.
1E is illegal.
1EE1 is illegal.
1.1.1E1 is illegal.
###7.6e+12.5 is illegal.
############1E1.1 is illegal.
+1.5e-1##2 is illegal.
+6-4.2 is illegal.
-75E- is legal.
-75E2- is illegal.
-3.3e-9999999999999999999999999 is legal.
# is illegal.
1.1E1 is legal.
###1.0e-55 is illegal.
##+4.1234567890E-99999 is illegal.
1.2 is legal.
1 is illegal.
###1. is illegal.
123.e123123123123123123+123123123123123123123 is illegal.
0e-0 is legal.
.1E1 is illegal.
-e-12 is legal.
-1e-12 is legal.
1E1 is legal.
1e1 is legal.
5e6 is legal.
5.2#####7 is illegal.
abcd is illegal.
########################1.2########################1.2 is illegal.
123-E12 is illegal.
123.0e12E is illegal.
5#e*6 is illegal.
is illegal.
5#e#6 is illegal.
1#E1 is illegal.
####6.5E is illegal.
#e-12 is illegal.
####1e-12 is illegal.
########################1.2 is illegal.
is illegal.
[/code] :(

superyoga
New poster
Posts: 3
Joined: Sat Oct 09, 2004 2:51 pm

Post by superyoga »

Why do not anyone answer my question?

:(

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

You don't even pass the sample output correctly.

Third line should be:
1.0e-55 is legal.

superyoga
New poster
Posts: 3
Joined: Sat Oct 09, 2004 2:51 pm

Post by superyoga »

I am so sorry. I thought I've changed spaces to # correctly.

Now I put a "correct" output generated by program:


1.2 is legal.
1. is illegal.
1.0e-55 is legal.
e-12 is illegal.
6.5E is illegal.
1e-12 is legal.
+4.1234567890E-99999 is legal.
7.6e+12.5 is illegal.
99 is illegal.
is illegal.
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.
123.456+789 is illegal.
1e+ is illegal.
.1111 is illegal.
123.0e12. is illegal.
123.0e12+ is illegal.
123.0e12- is illegal.
EEEEEE is illegal.
+++++++ is illegal.
....... is illegal.
99 is illegal.
is illegal.
++1E1 is illegal.
1E--1 is illegal.
6.2. is illegal.
-.5 is illegal.
6..2 is illegal.
1.1.1E11 is illegal.
-75- is illegal.
1E.1 is illegal.
.1E1 is illegal.
1E is illegal.
1EE1 is illegal.
1.1.1E1 is illegal.
7.6e+12.5 is illegal.
1E1.1 is illegal.
+1.5e-1 2 is illegal.
+6-4.2 is illegal.
-75E- is illegal.
-75E2- is illegal.
-3.3e-9999999999999999999999999 is legal.
is illegal.
1.1E1 is legal.
1.0e-55 is legal.
+4.1234567890E-99999 is legal.
1.2 is legal.
1 is illegal.
1. is illegal.
123.e123123123123123123+123123123123123123123 is illegal.
0e-0 is legal.
.1E1 is illegal.
-e-12 is legal.
-1e-12 is legal.
1E1 is legal.
1e1 is legal.
5e6 is legal.
5.2 7 is illegal.
abcd is illegal.
1.2 1.2 is illegal.
123-E12 is illegal.
123.0e12E is illegal.
5 e*6 is illegal.
is illegal.
5 e 6 is illegal.
1 E1 is illegal.
6.5E is illegal.
e-12 is illegal.
1e-12 is legal.
1.2 is legal.
is illegal.


Thanks a lot UFP2161.

But I got WA again... :(

Please help me...

sahand
New poster
Posts: 19
Joined: Sat Mar 12, 2005 5:56 pm
Location: Halifax, Nova Scotia, Canada
Contact:

325 - Pascal real numbers - WA - please help!

Post by sahand »

This is my code for 325, but I keep getting WAs!
I checked all the sample inputs on this board, and it gives correct output.
I would really appreciate if somebody could tell me what i'm doing is wrong.

P.S. I know it's not an efficient way of doing it. I know about FSMs but just didn't feel like doing them!

Code: Select all

Code removed!
Last edited by sahand on Thu Apr 28, 2005 2:58 pm, edited 2 times in total.

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

Are you really sure your end condition works?!

It did not when I tested your program.

sahand
New poster
Posts: 19
Joined: Sat Mar 12, 2005 5:56 pm
Location: Halifax, Nova Scotia, Canada
Contact:

Post by sahand »

Yes, I checked that. I was not correct but I corrected it and I still get WA.
Here's the new code:

Code: Select all

code removed
Thanks!
Last edited by sahand on Thu Apr 28, 2005 2:57 pm, edited 1 time in total.

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

input:

Code: Select all

457693476987495864364.5645634564564356e4563564564356543
457693476987495864364.5645634564564356e+4563564564356543
457693476987495864364.5645634564564356e-4563564564356543
+457693476987495864364.5645634564564356e4563564564356543
-457693476987495864364.5645634564564356e4563564564356543
457693476987495864364.+5645634564564356e4563564564356543
457693476987495864364.-5645634564564356e4563564564356543
*
my output:

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.
your output:

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.
See what I mean?

Your program seems to put extra spaces in front of 'is legal' or 'is illegal'.
I don't use C++, so I don't know how the built-in trim-function works but you should probably check for \0.

Hope it helps.

sahand
New poster
Posts: 19
Joined: Sat Mar 12, 2005 5:56 pm
Location: Halifax, Nova Scotia, Canada
Contact:

Post by sahand »

Thanks a lot, I got AC :)
It was a very simple mistake!

shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

Post by shakil »

Why WA??? please help.....

Code: Select all

Cut after AC.
SHAKIL

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: WA~ problem 325 Identifying Legal Pascal Real Constants

Post by abid_iut »

please help me
I am getting WA
here is my code:

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;
}
pls help :(
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: WA~ problem 325 Identifying Legal Pascal Real Constants

Post by mf »

Input:

Code: Select all

test
Your program's output is: "test is legal." I think it speaks for itself.

You're also not reading the input properly. scanf("%s", line) reads a single whitespace-delimited token, not a whole line.

Post Reply

Return to “Volume 3 (300-399)”