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

给你棋子所在的位置,让你求可以移动到的位置,处理好边界位置就好,基本是送分题

AC代码

#include<iostream>
#include<stdio.h>
using namespace std;
int dir[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1};
int main()
{char c;int ans=0;int x,y;cin>>c>>x;y=c-'a'+1;for(int i=0;i<8;i++){int tx=x+dir[i][0];int ty=y+dir[i][1];if(tx<=0||ty<=0||tx>8||ty>8) continue;ans++;}cout<<ans<<endl;return 0;
}

King Moves 水题相关推荐

  1. CodeForces - 3A Shortest path of the king【水题】

    [题目描述] The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, ...

  2. 【HDU - 1326】Box of Bricks(模拟水题)

    题干: Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds ...

  3. Coderforces 字符串水题合集

    今天我们聊聊 Coderforces 字符串水题合集. 字符串就是string. 这是string的百度翻译,我们要谈的是画框的.↓ string是C++.java.VB等编程语言中的字符串,字符串是 ...

  4. [总结:]BZOJ水题70题留念

    时间过得很快,转眼间BZOJ已经做了70道水题了.现在做一个整理 1001:狼抓兔子:平面图最小割转化为最短路,主要麻烦再建图 1002:轮状病毒:行列式+高精度 1008:越狱:快速幂+组合数学 1 ...

  5. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  6. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

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

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

  8. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  9. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

最新文章

  1. Logistic Regression--逻辑回归算法汇总
  2. hdu1032 Train Problem II (卡特兰数)
  3. iOS开发日记1-tableview编辑
  4. Linux Centos安装步骤
  5. 【LeetCode】3月19日打卡-Day4
  6. 开机一直转圈_电脑开机后网络一直转圈,程序也打不开?
  7. java程序设计教程(项目式)_《Java程序设计项目化教程(第2版)》怎么样_目录_pdf在线阅读 - 课课家教育...
  8. WCF中常见的几种Host,承载WCF服务的方法
  9. UGUI LongText
  10. 我们需要什么样的应急手册(佐岸)
  11. windows双系统完全删除ubuntu
  12. ZooKeeper使用场景
  13. Lightroom 2020年2月版新增功能
  14. android视频动态壁纸app,手机壁纸视频动态壁纸
  15. 12星座经典情爱语录
  16. Web服务器群集——编译安装Apache构建虚拟主机
  17. Microsoft Visusl C++2010运行程序时,调试弹出黑框自动闪退无法看见运行结果的解决方法
  18. 怎么设置360主页的html,360安全浏览器怎么设置主页 设置主页原来这么简单
  19. SpringBoot配置websocket
  20. 解决虚拟机桥接网络没有 VMnet0 的问题

热门文章

  1. Maven创建servlet项目演示(三)
  2. css方法div固定在网页底部
  3. 异构计算完全解析-CSDN.NET
  4. 基于SGIP协议编写短信网关接口
  5. 指针学习4--合成析构函数做了什么
  6. 改变TFS本地映射路径.
  7. python的*args与**kwargs
  8. linux 修改普通用户的 max user process
  9. 湖南省第六届大学生计算机程序设计竞赛---数字整除
  10. ios基础篇(十二)——UINavgationController的使用(三)ToolBar