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

why Runtime Error?
Posted by Kayzer 26 Nov 2014 00:07
import java.io.IOException;
import java.util.Scanner;

public class chess {
    static Scanner scn = new Scanner(System.in);
    public static void main(String args[]) throws IOException{
        int n=scn.nextInt();
        int[] g = new int[n];
        for (int i=0; i<n; i++){
            g[i]=game(i);

        }
        System.out.println("");
        for (int i=0; i<n; i++){
            System.out.println(g[i]);

        }
    }
    private static int game(int q) throws IOException{
        int b = 0, c, f=0;
        b=count(b);
        c=scn.nextInt();
        if (b-1>0 && c-2>0 && b-1<=8 && c-2<=8) f++;
        if (b+1>0 && c+2>0 && b-1<=8 && c-2<=8) f++;
        if (b+1>0 && c+2>0 && b+1<=8 && c+2<=8) f++;
        if (b-1>0 && c-2>0 && b+1<=8 && c+2<=8) f++;
        if (c+1>0 && b-2>0 && c+1<=8 && b-2<=8) f++;
        if (c-1>0 && b+2>0 && c-1<=8 && b+2<=8) f++;
        if (c+1>0 && b-2>0 && c-1<=8 && b+2<=8) f++;
        if (c-1>0 && b+2>0 && c+1<=8 && b-2<=8) f++;
        return f;

    }
    private static int count(int x) throws IOException{
        char cd;
            cd = (char) System.in.read();
        if (cd=='a') x=1;
        if (cd=='b') x=2;
        if (cd=='c') x=3;
        if (cd=='d') x=4;
        if (cd=='e') x=5;
        if (cd=='f') x=6;
        if (cd=='g') x=7;
        if (cd=='h') x=8;
        return x;

    }

}