zoukankan      html  css  js  c++  java
  • [Educational Codeforces Round 16]A. King Moves

    [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;
    }
    
  • 相关阅读:
    L1-046. 整除光棍
    判断素数
    L1-025. 正整数A+B
    L1-023. 输出GPLT
    L1-020. 帅到没朋友
    L1-016. 查验身份证
    L1-011. A-B
    UVa 400 Unix Is命令
    Uva 136 丑数
    The Preliminary Contest for ICPC Asia Xuzhou 2019 K. Center
  • 原文地址:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5806704.html
Copyright © 2011-2022 走看看