|
|
back to boardvery 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 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 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 But can you tell me the reason using Longint excepted byte? thankx |
|
|