zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    生活有时候就是个戏本
    Android dp、dpi、px
    iOS10以后相机、相册等授权问题
    iOS圆角性能问题
    激荡10年,珍贵的毕业礼物
    Android API 指南
    Android 配置
    Android Error
    安卓 MIUI真机测试
    iOS 同一段文字显示不同颜色
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5801839.html
Copyright © 2011-2022 走看看