ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1262. Pseudo-Roman Number

very interesting!! there 2 code
Posted by Bobur 26 Oct 2008 19:04
   var
   s : integer;
   ch : char;

begin
   s := 0;
   while not eof do
     begin
       read(ch);
       case ch of
       '1', '5' : inc(s);
       '2', '4', '6', '9' : inc(s, 2);
       '3', '7' : inc(s, 3);
       '8' : inc(s, 4);
       end;
     end;
   writeLn(s);
end.
this ic gave me AC!!

   var
   s : integer;
   ch : char;
   a : array ['0'..'9'] of byte = (0, 1, 2, 3, 2, 1, 2, 3, 4, 2);

begin
   s := 0;
   while not eof do
     begin
       read(ch);
       s := s + a[ch];
     end;
   writeLn(s);
end.
and this WA#1!!!!
i don't know why, who can explain it to me!!
thanks!!
Re: very interesting!! there 2 code
Posted by trc-pskov 8 Dec 2008 22:05
i don't know what it mean in pascal, but in C it is "address to non-existent element of memory"

take one correction:

read(ch);
//insert here:
if ((ch<'0') or (ch>'9')) then break;

s := s + a[ch];
.....


and sorry for my bad english


Edited by author 08.12.2008 22:11
Re: very interesting!! there 2 code
Posted by Artem Ladik 24 Mar 2009 13:59
this is my program:

const a:array['0'..'9'] of longint=(0,1,2,3,2,1,2,3,4,2);

var k:char;
    s:longint;
begin
 s:=0;
 while not EOln do
  begin
   read(k);
   inc(s,a[k]);
  end;
 write(s);
end.

use longint, not byte;)
Re: very interesting!! there 2 code
Posted by yangdong 23 Oct 2010 19:03
But can you tell me the reason using Longint excepted byte?
thankx