458 - The Decoder

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

Moderator: Board moderators

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: O.L.E. in 458

Post by CDiMa »

midra wrote:I get Output Limit Exceeded
WHY???

here is my code:
[c][...]
while(scanf("%c",&c)!=NULL)
[/c]

scanf returns the number of items assigned or EOF. Check against 1 (since you are reading only one character) or EOF.
midra wrote:[c][...]
i=1;
}
i++;
}[/c]
After the first line you start with i=2.
So you are printing 1 char in excess for every line after the first.

Ciao!!!

Claudio
midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra »

Thank you very much Dejarik and CDiMa.
I finally got AC...I just have to change NULL to EOF and i=1 to i=0

Dejarik Wrote:
PD: Why do you need an array to store chars if you manage them individually with scanf((char))? Try to store each char readed in a simple char variable and then print it with -7 ascii code. It should also works saving a lot of memory space, isn't it?
sorry for my ignorance but I am a newcomer in this field...I learn C about three or four months... I don't know what you mean...
Can you give me an example, please???
thanks a lot!!

Pd: Claudio? Where are you from? Are you from Argentina?? In my country it's a very common name...

Byeee and good luck.

Michel
CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Post by CDiMa »

midra wrote:Pd: Claudio? Where are you from? Are you from Argentina?? In my country it's a very common name...
Nope, I'm Italian ;)

Ciao!!!

Claudio
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

The "good" way to do it (the way I do it anyhow) is this:

Code: Select all

while ( 1 == scanf("%c", &t ) )
So either it returns EOF or doesn't read an character, it'll exit the loop..
midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra »

Thank you larry!!!
:D :D :D

good luck!bye
wyanez
New poster
Posts: 8
Joined: Thu Nov 20, 2003 7:19 pm

Post by wyanez »

You need to take into account the characters \n (13) and \r (10) (they do not in rank > = the 39 and > = 126 ).
this code it is sufficient:

[java] while((c=System.in.read())>=0){
if(c!=13 && c!=10) car=(char) (c-7);
else car=(char) c;
System.out.print (car);
}
[/java]

Good Luck!
Zoe
New poster
Posts: 9
Joined: Tue Jul 20, 2004 5:46 am
Location: Taiwen

458 in C WA

Post by Zoe »

Hi everyone.
I don't know why always take WA.
Please give me some hints.
Thanks!

[c]
#define max 1000

#include <stdio.h>

main()
{
int i;
char pwd[max];

while ( fgets(pwd, max, stdin) )
{
for ( i = 0 ; i < max ; i++ )
{
if ( pwd == '\0')
break;

pwd = pwd - 7;
printf("%c", pwd);
}

printf("\n");
}

}
[/c]
abishek
Experienced poster
Posts: 131
Joined: Mon Dec 15, 2003 5:41 am

Post by abishek »

fgets also stores the newline character in the array.
so you were also printing the '\n'-7.
and the judge only compares the files literally, and so you got WA.
i did the follwing and got AC

made max 2000000
replaced pwd=='\0' by pwd=='\n'
and got AC

all the best
abi
Zoe
New poster
Posts: 9
Joined: Tue Jul 20, 2004 5:46 am
Location: Taiwen

Thanks!

Post by Zoe »

Thanks abishek!
I got AC.
pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea

458 why is my code slower ?

Post by pipo »

my c++ code run 0.2 sec.. but, some codes only 0.0xxx... why ??

my code is very simple...

who can help me ?

:( :evil:

Code: Select all

#include <stdio.h>

void main(void)
{
	char line[512];
	int i;

	while ( gets(line) ) 
	{
		i = 0;

		while ( line[i] )
			printf("%c", line[i++]-7);

		printf("\n");
	}
}
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker »

:D Hi, when I solved this problem for the 1st time I was a beginner and the only thing I cared then was to get Ac. my old code was slow, it took
0:00.264 to get Ac.

after I saw your code , i tried to make it faster and got Ac in 0:00.088 and 64 memory
so have a look at this....

Code: Select all


#include<stdio.h>

void main()
{
     char temp;

     while((temp=getchar())!=EOF)
     {
           (temp==10)?putchar(temp):putchar(temp-7);
     }
}
Jalal : AIUB SPARKS
pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea

Post by pipo »

CodeMaker.. thank a lot...

well.... could you please explain to me ???

why is a preformance of two codes wrong ?

in my opinion, two codes are very simple..

in my code, just use gets function..

but, in your code, use getchar and putchar functions..


is this that reason ??
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker »

Yes, that's the reason and I also used conditional operators,executed less lines in my code....

many things are behind our eyes and those are written in the structures of different built-in functions that we use....some functions works faster because they work simple....

to speed things up, we also have to consider these things....there must be even batter ways then mine, and that's why people got Ac in 0.00.000 time.
Jalal : AIUB SPARKS
pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea

Post by pipo »

that's good.. i see exactly...

thank you, CodeMaker...
yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

decoding 458

Post by yogeshgo05 »

hi guys,
here's my code
judge says wa
# include <stdio.h>


int main()
{
char ch;
int i;



while((ch=getchar())!=EOF)
{
i=ch-7;
putchar(i);

}

return 0;
}
Post Reply

Return to “Volume 4 (400-499)”