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

Help! I have wrong answer, but I don't understand why
Posted by Grigorenko Vlad 12 May 2012 00:53
#include<stdio.h>

int function(char,int);

int main(void){
    int i,b,n;
    int arr[1001];
    char a;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%1s",&a);
        scanf("%d",&b);
        arr[i]=function(a,b);
    }
    for(i=1;i<=n;i++)
        printf("%d\n",arr[i]);
return 0;
}

int function(char a, int b){
        int kil;
        if(a>='c' && a<='f' && b>=3 && b<=6)
            kil=8;
        else
            if(((b==2 || b==7) && a>='c' && a<='f') || (b>=3 && b<=6 && (a=='b' || a=='g')))
                kil=6;
        else
            if((a=='a' || a=='h') && (b==1 || b==8))
                kil=2;
        else
            if(((a=='a' || a=='h') && (b==7 || b==2 )) || ((a=='b' || a=='g') && (b==1 || b==8 )))
                kil=3;
        else
            kil=4;
return kil;
}