CodeForces-710A. King Moves
来源:互联网 发布:同济大学软件研究生 编辑:程序博客网 时间:2024/04/30 21:51
The 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<iostream>using namespace std;int main(){ char c, x; int dir[8][2] = { {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1} }; int d, y, number = 0; cin >> c >> d; for (int i = 0; i < 8; i++) { x = c + dir[i][1]; y = d + dir[i][0]; if (x >= 'a'&&x <= 'h'&&y >= 1 && y <= 8) number++; } cout << number << endl; return 0;}
0 0
- 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】Codeforces 710A King Moves
- CodeForces 710A King Moves(第一次打CF)
- Educational Codeforces Round 16 A. King Moves
- 【CodeForces】〖 Educational Codeforces Round 16〗A. King Moves
- A. King Moves
- Codeforces刷题之路——710A King Moves
- Educational Codeforces Round 16 A. King Moves【模拟】
- codeforces710A--King Moves水
- CodeForces 370A Rook, Bishop and King
- CodeForces 370A Rook, Bishop and King
- CODEFORCES 526 A. King of Thieves
- CodeForces 526A-King of Thieves
- codeforces 3A - Shortest path of the king
- C#入门9.13——类的多态
- PHP学习:函数
- struts.xml(一)的<action-mappings>标签详解
- Fragment异常:Binary XML file line XXX: Error inflating class fragment
- 看到一张比较好的关于特征工程的图
- CodeForces-710A. King Moves
- 计算机网络-传输层
- android开发艺术探索(四)
- 检测App的内存占用和泄漏
- java 正则表达式使用
- leancloud对图片处理
- spring学习总结(四)
- MPEG2-TS音视频同步原理(PCR dts pts)
- MemoryMonitor--内存清理和Pss监控工具