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

ac c++
Posted by lhyx1990 24 Jan 2014 20:07

#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

class Place {
public:
    char x;
    int y;

    bool isOnboard() {
        if (x < 'a' || x > 'h' || y < 1 || y > 8) return false;
        return true;
    }



    Place(char x, int y) {
        this->x = x;
        this->y = y;
    }

};



int main(int argc, const char * argv[])
{
    int N;
    cin >> N;


    vector<Place> places;

    for (int i = 0; i < N; i++) {
        char x;
        int y;
        cin.get(x);

        if (x == '\n') {
            i--;
            continue;
        }

        cin >> y;

        Place place (x, y);
        places.push_back(place);

    }


    for (int i = 0; i < N; i++) {
        Place place = places[i];
        int moves = 0;


        //left 2 up 1
        place.x -= 2;
        place.y -= 1;
        moves += place.isOnboard();

        //left 2 down 1
        place.y += 2;
        moves += place.isOnboard();

        //right 2 down 1
        place.x += 4;
        moves += place.isOnboard();
        //right 2 up 1
        place.y -= 2;
        moves += place.isOnboard();

        //right 1 up 2
        place.x -= 1;
        place.y -= 1;
        moves += place.isOnboard();

        //left 1 up 2
        place.x -= 2;
        moves += place.isOnboard();

        //left 1 down 2
        place.y += 4;
        moves += place.isOnboard();

        //right 1 down 2
        place.x += 2;
        moves += place.isOnboard();

        cout << moves << endl;

    }



}

Edited by author 24.01.2014 20:07