[Educational Codeforces Round 16]A. King Moves

news/2024/7/7 22:36:39

[Educational Codeforces Round 16]A. King Moves

试题描述

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 dis 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).

输入

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'.

输出

Print the only integer x — the number of moves permitted for the king.

输入示例

e4

输出示例

8

数据规模及约定

题解

分支结构。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {if(Head == Tail) {int l = fread(buffer, 1, BufferSize, stdin);Tail = (Head = buffer) + l;}return *Head++;
}
int read() {int x = 0, f = 1; char c = getchar();while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }return x * f;
}char s[10];int main() {scanf("%s", s);if((s[0] == 'a' || s[0] == 'h') && (s[1] == '1' || s[1] == '8')) return puts("3"), 0;if((s[0] == 'a' || s[0] == 'h') || (s[1] == '1' || s[1] == '8')) return puts("5"), 0;puts("8");return 0;
}

 

转载于:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5806704.html


http://lihuaxi.xjx100.cn/news/266753.html

相关文章

苏炳添博士论文研究自己,奥运学术两兼顾,还是暨大副教授,网友:真正的Run数据...

点击上方“视学算法”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达萧箫 发自 凹非寺量子位 报道 | 公众号 QbitAI“我为什么能跑这么快&#xff1f;”这可不是调侃&#xff0c;而是“亚洲飞人”苏炳添的正经博士论文&#xff01;在题为《新时…

JVM 常用参数

常见参数配置 -XX:PrintGC 每次触发GC的时候打印相关日志-XX:UseSerialGC 串行回收-XX:PrintGCDetails 更详细的GC日志-Xms 堆初始值-Xmx 堆最大可用值-Xmn 新生代堆最大可用值-XX:SurvivorRatio 用来设置新生代中eden空间和from/to空间的比例.-XX:NewRatio 配置新生代与老年代…

用两个栈实现队列

用两个栈实现队列 【题目】&#xff1a; 用两个栈实现一个队列&#xff0c;实现这个队列的删除头部deleteHead和插入尾部appendTail的功能。 示例 1&#xff1a; 输入&#xff1a; ["CQueue","appendTail","deleteHead","deleteHead&quo…

Java 8 中的方法引用,轻松减少代码量,提升可读性!

点击上方蓝色“方志朋”&#xff0c;选择“设为星标”回复“666”获取独家整理的学习资料&#xff01;1. 引言Java8中最受广大开发中喜欢的变化之一是因为引入了 lambda 表达式&#xff0c;因为这些表达式允许我们放弃匿名类&#xff0c;从而大大减少了样板代码&#xff0c;并提…

干货 | 一文完全理解AUC-ROC曲线

点击上方“小白学视觉”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达来源&#xff1a; https://towardsdatascience.com/understanding-auc-roc-curve-68b2303cc9c5 翻译&#xff1a;石头 机器学习模型的性能测量是一项必不可少的工作…

Io流的字节流与缓冲流

当我们队大量数据进行保存时可以用数组&#xff0c;当数据到达一定量时或给用户一个易懂得接口时就可采用IO流&#xff1a; IO流按进行的操作分输出流与输入流InputStream与OutputSteam 按操作的原理来分有2种常见的IO流字节流与缓冲流&#xff1a;这2种IO的的输入输出流都是对…

struts2请求处理过程源代码分析(1)

2019独角兽企业重金招聘Python工程师标准>>> 转载自&#xff1a;http://www.see-source.com/ 源码解析网 网上对于struts2请求处理流程的讲解还是比较多的&#xff0c;有的还是非常详细的&#xff0c;所以这里我就简单地将大概流程总结下&#xff0c;有了个大概印象…

python错误提示:TypeError: ‘builtin_function_or_method‘ object is not subscriptable

[] 换成 () >>> yy.replace[a,s] Traceback (most recent call last):File "<stdin>", line 1, in <module> TypeError: builtin_function_or_method object is not subscriptable >>> yy.replace(a,s) sbcdef >>>