A. King Moves
来源:互联网 发布:程序员健康问题 编辑:程序博客网 时间:2024/05/17 22:42
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputThe 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).
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<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main (){char a;int b,c=8;scanf("%c%d",&a,&b);if(((a=='a')||(a=='h'))&&((b==1)||(b==8))){c=3;}else if((a=='a')||(a=='h')||(b==1)||(b==8)){c=5;}printf("%d\n",c);return 0;}
0 0
- A. King Moves
- codeforces 710A-King Moves
- Codeforces 710A- King Moves
- CodeForces-710A. King Moves
- 【模拟】Codeforces 710A King Moves
- Codeforces Problem 710A King Moves(implementation)
- Educational Codeforces Round 16 A. King Moves
- CodeForces 710A King Moves(第一次打CF)
- 【CodeForces】〖 Educational Codeforces Round 16〗A. King Moves
- 【Educational Codeforces Round 16】Codeforces 710A King Moves
- Educational Codeforces Round 16 A. King Moves【模拟】
- codeforces710A--King Moves水
- Codeforces刷题之路——710A King Moves
- A - Knight Moves
- A*算法. Knight Moves
- poj2243 Knight Moves--A*
- A. King of Thieves
- A. King of Thieves
- Context
- 【Android】文件读写操作(含SDCard的读写)
- 电路设计_过压器件压敏电阻的选型建议
- 电路与Multisim基础 二极管的最大反向电压、平均正向电流、正向电压
- MySQL优化—工欲善其事,必先利其器之EXPLAIN
- A. King Moves
- Shader特效——“素描 Pencil Sketch”的实现【GLSL】
- 深入理解ButterKnife源码并掌握原理(四)
- Linux新手应掌握的10个基本命令
- 大话三轴加速度计
- 机器自动识别验证码的原理是怎么样的?
- 学习笔记:冒泡排序的C++、JavaScript、Java实现
- 晚上睡之前练习打字,打打吕鑫大师教我的
- 大话三轴地磁