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;
}

  

Educational Codeforces Round 16 A的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 16 E. Generate a String dp

    题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...

  7. Educational Codeforces Round 16 D. Two Arithmetic Progressions (不互质中国剩余定理)

    Two Arithmetic Progressions 题目链接: http://codeforces.com/contest/710/problem/D Description You are gi ...

  8. Educational Codeforces Round 16 E. Generate a String (DP)

    Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...

  9. Educational Codeforces Round 16

    A. King Moves water.= =. #include <cstdio> ,,,,,-,-,-}; ,-,,,-,,,-,}; #define judge(x,y) x > ...

  10. Educational Codeforces Round 16 A B C E

    做题太久也有点累了..难题不愿做 水题不愿敲..床上一躺一下午..离下一场div2还有点时间 正好有edu的不计分场 就做了一下玩玩了 D是个数学题 F是个AC自动机 都没看明白 留待以后补 A 给出 ...

随机推荐

  1. Android 发送短信与接收短信

    package com.example.testsms; import android.app.Activity; import android.app.PendingIntent; import a ...

  2. 夺命雷公狗---2016-linux---3之目录一般作用

    最好文件还是存放在自己的home目录下 建议:在很多时候如果需要系统备份最好去备份boot和etc这两个目录

  3. SQL 中常见的系统存储过程

    -- 来源于网络 -- 更详细的介结参考联机帮助文档 xp_cmdshell --*执行DOS各种命令,结果以文本行返回. xp_fixeddrives --*查询各磁盘/分区可用空间 xp_logi ...

  4. 《OpenGL着色语言》理解点记录二

    别人提到“OpenGL的处理管线”时,意味着什么? 准确的讲,应该是“OpenGL图形处理管线”,“管线”带有特定的顺序,在OpenGL中就是Graphics Processing Pipeline. ...

  5. [转载] 关关采集不能生成html的问题

    转载地址:http://www.pcliver.com/archives/814.html 关关不能生成html的问题: 1.关关设置的问题 2.模板标签关关不支持 排除法之后,得出我的网站是模板的问 ...

  6. Elasticsearch--配置文件

    config目录下有2个配置文件:es的配置文件:elasticsearch.yml日志配置文件:logging.yml,更多内容请参考:ELK教程 cluster.name: elasticsear ...

  7. android 学习随笔二十九(自定义监听 )

    package com.itheima.momo.dialog; import com.itheima.momo.R; import android.app.AlertDialog; import a ...

  8. xib中设置控件的圆角

    1.http://my.oschina.net/ioslighter/blog/387991?p=1 利用layer.cornerRadius实现一个圆形的view,将layer.cornerRadi ...

  9. 使用SQLServer Profiler侦测死锁(转)

    准备工作: 为了侦测死锁,我们需要先模拟死锁.本例将使用两个不同的会话创建两个事务. 步骤: 1. 打开SQLServer Profiler 2. 选择[新建跟踪],连到实例. 3. 然后选择[空白] ...

  10. 常用的rpm和yum的一些命令

    常用的rpm命令  rpm -qa | grep coreutils    <-- 查看系统上是否已经安装了coreutils  rpm -qi coreutils           < ...