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 1197. Lonesome Knight

20 lines AC
Posted by Don 11 Aug 2004 12:52
Here is my solution:
const dir:array[1..8,1..2] of shortint=
    ((2,1),(2,-1),(1,2),(1,-2),(-1,2),(-1,-2),(-2,1),(-2,-1));
var test,x,y,number,i:byte;
    s:string[2];
begin
 readln(test);
 while test>0 do
  begin
   dec(test);
   readln(s);
   x:=ord(s[1])-ord('a')+1;
   y:=ord(s[2])-ord('0');
   number:=0;
   for i:=1 to 8 do
    if (x+dir[i,1]>=1)and(x+dir[i,1]<=8)
    and(y+dir[i,2]>=1)and(y+dir[i,2]<=8)
     then inc(number);
   writeln(number);
  end;
end.
Re: 20 lines AC
Posted by Admin 13 Feb 2005 19:15
my - the best :))))

var s:string[2];
count,x,i,q,w:integer;
begin
readln(x);
for i:=1 to x do begin
readln(s);
if s[1]='a' then s[1]:='1';if s[1]='b' then s[1]:='2';
if s[1]='c' then s[1]:='3';if s[1]='d' then s[1]:='4';
if s[1]='e' then s[1]:='5';if s[1]='f' then s[1]:='6';
if s[1]='g' then s[1]:='7';if s[1]='h' then s[1]:='8';
count:=0;
for q:=1 to 8 do for w:=1 to 8 do
if ((q=ord(s[1])-ord('0')-1)and(w=ord(s[2])-ord('0')-2))or
   ((q=ord(s[1])-ord('0')-1)and(w=ord(s[2])-ord('0')+2))or
   ((q=ord(s[1])-ord('0')+1)and(w=ord(s[2])-ord('0')-2))or
   ((q=ord(s[1])-ord('0')+1)and(w=ord(s[2])-ord('0')+2))or
   ((q=ord(s[1])-ord('0')-2)and(w=ord(s[2])-ord('0')-1))or
   ((q=ord(s[1])-ord('0')-2)and(w=ord(s[2])-ord('0')+1))or
   ((q=ord(s[1])-ord('0')+2)and(w=ord(s[2])-ord('0')-1))or
   ((q=ord(s[1])-ord('0')+2)and(w=ord(s[2])-ord('0')+1)) then inc(count);
writeln(count);

end;
end.
Re: 20 lines AC
Posted by Taran_Alex 23 Sep 2007 07:09
#include <stdio.h>

int p[8][8]={2,3,4,4,4,4,3,2,
             3,4,6,6,6,6,4,3,
             4,6,8,8,8,8,6,4,
             4,6,8,8,8,8,6,4,
             4,6,8,8,8,8,6,4,
             4,6,8,8,8,8,6,4,
             3,4,6,6,6,6,4,3,
             2,3,4,4,4,4,3,2};
void main(void)
{
    int N;
    scanf("%i\n",&N);
    for(int i=0;i<N;i++)
    {
        char letter,digit;
        scanf("%c%c\n",&letter,&digit);
        int il,id;
        il=letter-'a'+1;
        id=digit-'0';
        printf("%i\n",p[il-1][id-1]);
    }
}
Re: 20 lines AC
Posted by Atik 14 Jan 2009 17:15
19 lines AC)))
var
  N,a,b,i:integer;
  c:char;
begin
  readln(N);
  for i:=1 to N do
    begin
    read(c);
    a:=ord(c)-ord('a')+1;
    if a>4 then a:=9-a;
    if a=4 then a:=3;
    readln(b);
    if b>4 then b:=9-b;
    if b=4 then b:=3;
    if a+b>4 then inc(a);
    if a+b>6 then inc(a);
    writeln(a+b);
    end;
end.