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

Работающая версия [Worked]
Posted by sovaz1997 28 Feb 2016 00:05
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int test_horse(int, int);
int test(string);

int test(string run) {
    return test_horse(run[0] - 'a', run[1] - '1');
}

int test_horse(int x, int y) {
    int count = 0;
    if(x + 1 < 8 && y + 2 < 8) {count++;}
    if(x + 1 < 8 && y - 2 >= 0) {count++;}
    if(x - 1 >= 0 && y + 2 < 8) {count++;}
    if(x - 1 >= 0 && y - 2 >= 0) {count++;}

    if(x + 2 < 8 && y + 1 < 8) {count++;}
    if(x + 2 < 8 && y - 1 >= 0) {count++;}
    if(x - 2 >= 0 && y + 1 < 8) {count++;}
    if(x - 2 >= 0 && y - 1 >= 0) {count++;}

    return count;
}

int main() {
    vector<string>vec;

    int N;
    cin >> N;

    for(int i = 0; i < N; ++i) {
        string str;
        cin >> str;
        vec.push_back(str);
    }

    for(int i = 0; i < vec.size(); ++i) {
        cout << test(vec[i]) << endl;
    }


}