CodeForce 710A King Moves

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 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代码:

 1 # include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     char ch1, ch2;
 6     scanf("%c%c", &ch1, &ch2);
 7     if(ch1 == ‘a‘ && ch2 == ‘1‘)
 8         printf("3\n");
 9     else if(ch1 == ‘a‘ && ch2 == ‘8‘)
10         printf("3\n");
11     else if(ch1 == ‘h‘ && ch2 == ‘1‘)
12         printf("3\n");
13     else if(ch1 == ‘h‘ && ch2 == ‘8‘)
14         printf("3\n");
15     else if(ch1 == ‘a‘ || ch1 == ‘h‘ || ch2 == ‘1‘|| ch2 == ‘8‘)
16         printf("5\n");
17     else
18         printf("8\n");
19     return 0;
20 }

				
时间: 2024-10-27 06:02:49

CodeForce 710A King Moves的相关文章

codeforces 710A King Moves(水)

output standard output 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

CodeForces 710A King Moves (水题)

题意:给定一个坐标,问你皇后有几个方向可以走. 析:直接格举那八个方向即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring&g

【模拟】Codeforces 710A King Moves

题目链接: http://codeforces.com/problemset/problem/710/A 题目大意: 国际象棋标准8X8棋盘,国王能往周围8个方向走.输入国王的位置,输出当前国王能往几个方向走. 题目思路: [模拟] 签到题(看错题目WA了一次).边界处理下就好. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorithm> 6 #in

codeforces 710A A. King Moves(水题)

题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include &l

Educational Codeforces Round 16---部分题解

710A. King Moves 给你图中一点求出它周围有几个可达的点: 除边界之外都是8个,边界处理一下即可: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<cctype> #include<queue> #include<stack> #include<v

Educational Codeforces Round 16

A. King Moves water.= =. 1 #include <cstdio> 2 int dx[] = {0,0,1,1,1,-1,-1,-1}; 3 int dy[] = {1,-1,0,1,-1,0,1,-1,0}; 4 #define judge(x,y) x >= 1 && x <= 8 && y >= 1 && y <= 8 5 int main() 6 { 7 char t; 8 int x, y,

Codeforces710

[未完待续] A 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. King moves from the pos

codeforce 128C Games with Rectangle 排列组合

Games with Rectangle Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n?×?m rect

CF3A Shortest path of the king

The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, h