Page 2 of 5

Re: O.L.E. in 458

Posted: Tue Apr 27, 2004 10:16 am
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

Posted: Wed Apr 28, 2004 4:32 am
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

Posted: Wed Apr 28, 2004 9:02 am
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

Posted: Wed Apr 28, 2004 9:14 am
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..

Posted: Thu Apr 29, 2004 5:20 am
by midra
Thank you larry!!!
:D :D :D

good luck!bye

Posted: Sat Jun 26, 2004 10:06 pm
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!

458 in C WA

Posted: Tue Jul 20, 2004 5:57 am
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]

Posted: Tue Jul 20, 2004 6:31 am
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

Thanks!

Posted: Tue Jul 20, 2004 7:25 am
by Zoe
Thanks abishek!
I got AC.

458 why is my code slower ?

Posted: Sat Jan 22, 2005 6:47 am
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");
	}
}

Posted: Sat Jan 22, 2005 12:26 pm
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);
     }
}

Posted: Sat Jan 22, 2005 1:12 pm
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 ??

Posted: Sat Jan 22, 2005 3:12 pm
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.

Posted: Sat Jan 22, 2005 6:30 pm
by pipo
that's good.. i see exactly...

thank you, CodeMaker...

decoding 458

Posted: Mon Jan 30, 2006 11:32 am
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;
}