Page 1 of 5

Posted: Wed Feb 27, 2002 9:03 am
by edmanm
Can anybody give me some sample input to use to test my program for #458? My program works with the sample input given on the website, but I still get a W.A. What's the tricky input on this one??

Posted: Thu Feb 28, 2002 5:20 am
by pochmann
The input contains characters outside of ASCII range, that is, larger than 127. Maybe you use signed char and don't translate it when it's smaller than 32+7 or sth like that?

If that doesn't help, would you mind posting your solution?

Stefan

Posted: Thu Feb 28, 2002 6:26 am
by edmanm
Here's my code so far. Am I on the right track?:

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>

main()
{

char coded[3000];
char decoded[3000];
int length, i;
int key;

gets(coded);
key = coded[0] - '*';

do
{
length = strlen(coded);

for(i=0;i<length;i++)
decoded = coded - key;

for(i=0;i<length;i++)
printf("%c", decoded);

printf("n");
}while(gets(coded));

return 0;

}

Posted: Thu Feb 28, 2002 6:56 am
by pochmann
Yes you are. But the key is always 7. Maybe that's your problem. Wasn't stated in the description, very bad.

Stefan

Posted: Thu Feb 28, 2002 7:29 am
by edmanm
That was all I had to change! I was under the impression that the key could be something other than 7, but I was wrong.

Thank you much pochmann!!

ACM #458: What's wrong?

Posted: Fri Jun 28, 2002 1:24 pm
by ec3_limz
I keep getting wrong answer. What's wrong?

--------------------------------------------------------------------------------------
/* @JUDGE_ID: 18472 458 C++ */

#include <stdio.h>
#include <string.h>

int main() {
char line[256];
int len, i;

while (!feof(stdin)) {
gets(line);

len = strlen(line);
for (i = 0; i < len; i++)
printf("%c", static_cast<char>(line - 7));
printf("%c", '\n');
}

return 0;
}[/cpp]

Posted: Fri Jun 28, 2002 1:39 pm
by Picard
your end condition is false. feof() returns true only after one read function failed. in this the last line is repeated twice. solution:

Code: Select all

for (;;) {
  gets(line);
  if (feof(stdin))
    break
...
or simpler:

Code: Select all

while (gets(line)) {
...
[/code]

458 - help me with speed!

Posted: Sat Aug 10, 2002 5:00 am
by liusu
the problem 458:
my pascal code run 5.1 second ,but c++ code only 0.2 seconds,why?
who can help me?

:cry: :evil:
[pascal]var
str:string;
i:integer;
begin
while not eof do
begin
readln(str);
for i:=1 to length(str) do
write(chr(ord(str)-7));
writeln;

end;
end.[/pascal]

Re: help me with speed!

Posted: Thu Sep 25, 2003 6:46 am
by 36495KN
me too!
and I consider why it use 324KBytes for the program?
:cry:

Your PASCAL program has solved Ok the problem 458 (The Decoder)
in 3.742 seconds using as much as 324 kbytes of virtual memory.
Congratulations

liusu wrote:the problem 458:
my pascal code run 5.1 second ,but c++ code only 0.2 seconds,why?
who can help me?

:cry: :evil:
[pascal]var
str:string;
i:integer;
begin
while not eof do
begin
readln(str);
for i:=1 to length(str) do
write(chr(ord(str)-7));
writeln;

end;
end.[/pascal]

by this code, 0.338 seconds, 320Kbytes

Posted: Thu Sep 25, 2003 7:50 am
by 36495KN
[pascal]
var s1: string;
l1, i: integer;
ch1: char;

begin
while (not eof) do begin
readln(s1);
l1:= length(s1);

for i:=1 to l1 do begin
ch1:= s1;
ch1:= chr((ord(ch1)) - (ord('J')) + (ord('C')));
s1:= ch1;
end;
writeln(s1);
end;
end.
[/pascal]

:D

Posted: Thu Sep 25, 2003 2:25 pm
by little joey
Accepted (P.E.) in 0.070 sec:
[pascal]program p458;

var
line:ansistring;
buffer:ansistring;
bufptr:integer;
inptr:^char;
begin
setlength(buffer,1000000);
bufptr:=0;
while not eof do begin
readln(line);
inptr:=@line[1];
while(inptr^<>#0) do begin
inc(bufptr);
buffer[bufptr]:=chr(ord(inptr^)-7);
inc(inptr);
end;
inc(bufptr);
buffer[bufptr]:=#13;
inc(bufptr);
buffer[bufptr]:=#10;
end;
setlength(buffer,bufptr);
writeln(buffer);
end.[/pascal]

I'm not shure how to get rid of the P.E., but who cares...
Write and writeln are very slow compared to their C pendants, so to gain speed in an output intensive problem, you have to do your own buffering.

B.t.w. read and readln don't have that slowness: all the data for this problem is read in 0.027 sec using readln statements as above.

Notice that there are also 0.000 sec submissions in the ranking. These times are impossible, because you can't read and write all the judges data in this small amount of time. Obviously there are ways to fool the judge...

458 - The Decoder

Posted: Thu Mar 25, 2004 9:51 pm
by Jed Humphries
I am a new poster and I have been trying to get this program accepted but I cant seem to make it accept it and I have read all the notes about Java. Can any of you java gurus help me out with this code:[java]
import java.io.*;
class Main
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}

catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null); // eof

return (new String (lin, 0, lg));
}

public static void main(String [] args) throws IOException
{
Main myWork = new Main(); // create a dinamic instance
//check to see if the next char is printable
while(((int)System.in.read()>=39)||((int) System.in.read()>=126))
myWork.Begin();
}
void Begin()
{
String input="", output="";
input = ReadLn(255);
input = input.substring(0,input.length()-1);
for (int i=0; i<input.length(); i++)
output = output + (char) (input.charAt(i)-7);

System.out.println(output);
}
}[/java]

458 RunTimeError

Posted: Fri Apr 02, 2004 9:25 pm
by Wane
i've try if(get()==EOF)break;
but i didn't work
please help me

#include <stdio.h>


int main(){
char* sentence;

int i;
while(sentence[0]!='\0'){

gets(sentence);

for(i=0;sentence!='\0';i++){
sentence=sentence-7;
}
printf("%s\n",sentence);

}

return 0;
}

O.L.E. in 458

Posted: Tue Apr 27, 2004 3:20 am
by midra
I get Output Limit Exceeded
WHY???

here is my code:
[c]#include <stdio.h>


int main()
{
char c[1000001];
int i=1,j; /*counters*/

while(scanf("%c",&c)!=NULL)
{
if (c=='\n')
{
for (j=1;j<=(i-1);j++)
printf("%c",c[j]-7);
printf("\n");
i=1;
}
i++;
}
return 0;
}[/c]

please help me!!!

Posted: Tue Apr 27, 2004 9:27 am
by Dejarik
Maybe replacing

Code: Select all

while(scanf("%c",&c[i])!=NULL)
with

Code: Select all

while(scanf("%c",&c[i])!=EOF)
will work?

Hope it helps...

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?

Joan