• Educational Codeforces Round 16 A


    Description

    he only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king.

    Check the king's moves here https://en.wikipedia.org/wiki/King_(chess).

    King moves from the position e4
    Input

    The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.

    Output

    Print the only integer x — the number of moves permitted for the king.

    Example
    input
    e4
    output
    8
    题意:求棋子放在不同位置能走几个方向
    解法:模拟+讨论边界情况
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        string s;
        cin>>s;
        if(s[0]=='a'&&s[1]=='8')
        {
            cout<<"3"<<endl;
            return 0;
        }
        else if(s[0]=='h'&&s[1]=='8')
        {
            cout<<"3"<<endl;
            return 0;
        }
        else if(s[0]=='a'&&s[1]=='1')
        {
            cout<<"3"<<endl;
            return 0;
        }
        else if(s[0]=='h'&&s[1]=='1')
        {
            cout<<"3"<<endl;
            return 0;
        }
        else if(s[0]=='a'&&(s[1]>='1'&&s[1]<='7'))
        {
            cout<<"5"<<endl;
            return 0;
        }
        else if(s[0]=='h'&&(s[1]>='1'&&s[1]<='7'))
        {
            cout<<"5"<<endl;
            return 0;
        }
        else if((s[0]>='b'&&s[0]<='g')&&(s[1]=='8'))
        {
            cout<<"5"<<endl;
            return 0;
        }
        else if((s[0]>='b'&&s[0]<='g')&&(s[1]=='1'))
        {
            cout<<"5"<<endl;
            return 0;
        }
        else
        {
            cout<<"8"<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    Weak Events in C#【译】
    Architecture
    在VS2012中使用NuGet引入Prism
    UIA Verify简介(未完待续)
    inspect无法抓到窗口控件详细信息
    从CSDN搬至博客园
    VC改变CListCtrl 表格中文字颜色,和背景颜色。
    vc 播放音乐
    VC字体对话框的初始化
    javac -cp java -cp
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5801839.html
Copyright © 2020-2023  润新知