Codeforces Educational Round 16 A.King Moves

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(false)

int ret(char ch)
{
    if(ch == 'a') return 1;
    else if(ch == 'b') return 2;
    else if(ch == 'c') return 3;
    else if(ch == 'd') return 4;
    else if(ch == 'e') return 5;
    else if(ch == 'f') return 6;
    else if(ch == 'g') return 7;
    else if(ch == 'h') return 8;
}

int ar[9][9];

void init()
{
    int i,j;

    for(i=1; i<=8; i++)
    {
        for(j=1; j<=8; j++)
        {
            ar[i][j] = 1;
        }
    }
}

int main()
{
    fast;
    int n;
    char c;
    init();
    while(cin >> c >> n)
    {
        int i = n;
        int j = ret(c) , cnt=0; //cout << ar[i][j] << "\n"; return 0;

        if(ar[i-1][j+1]==1)cnt++;
        if(ar[i][j+1]==1)cnt++;
        if(ar[i-1][j]==1)cnt++;
        if(ar[i-1][j-1]==1)cnt++;
        if(ar[i][j-1]==1)cnt++;
        if(ar[i+1][j]==1)cnt++;
        if(ar[i+1][j+1]==1)cnt++;
        if(ar[i+1][j-1]==1)cnt++;

        cout << cnt << "\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number