The statement of this problem is very simple: you are to determine how many squares of the chessboard can be attacked by a knight standing alone on the board. Recall that a knight moves two squares forward (horizontally or vertically in any direction) and then one square sideways (perpedicularly to the first direction).

Input

The first line contains the number N of test cases, 1 ≤ N ≤ 100. Each of the following N lines contains a test: two characters. The first character is a lowercase English letter from 'a' to 'h' and the second character is an integer from 1 to 8; they specify the rank and file of the square at which the knight is standing.

Output

Output N lines. Each line should contain the number of the squares of the chessboard that are under attack by the knight.

Sample

input output
3
a1
d4
g6
2
8
6
Problem Author: folklore Problem Source: Fifth High School Children Programming Contest, Ekaterinburg, March 02, 2002
// Ural Problem 1197. Lonesome Knight
// Verdict: Accepted
// Submission Date: 10:31:16 14 Jan 2014
// Run Time: 0.015s
//
// 版权所有(C)acutus。(mail: acutus@126.com)
// 博客:http://www.cnblogs.com/acutus/
// [解题方法]
// 简单题,直接按题意判断即可 #include<stdio.h> int countNumber(int i, int j)
{
int count = ;
if((i - ) >= ) {
if((j - ) >= ) count++;
if((j + ) <= ) count++;
}
if((i - ) >= ) {
if((j - ) >= ) count++;
if((j + ) <= ) count++;
}
if((i + ) <= ) {
if((j - ) >= ) count++;
if((j + ) <= ) count++;
}
if((i + ) <= ) {
if((j - ) >= ) count++;
if((j + ) <= ) count++;
}
return count;
} void solve()
{
int N, n;
char c;
scanf("%d", &N);
getchar();
while(N--) {
scanf("%c%d", &c, &n);
getchar();
printf("%d\n",countNumber(c - 'a' + , n));
}
} int main()
{
solve();
return ;
}

Ural 1197 - Lonesome Knight的更多相关文章

  1. LeetCode 1197. Minimum Knight Moves

    原题链接在这里:https://leetcode.com/problems/minimum-knight-moves/ 题目: In an infinite chess board with coor ...

  2. Ural 1298 Knight 题解

    目录 Ural 1298 Knight 题解 题意 题解 程序 Ural 1298 Knight 题解 题意 给定一个\(n\times n(1\le n\le8)\)的国际象棋棋盘和一个骑士(基本上 ...

  3. 【计算几何】URAL - 2101 - Knight's Shield

    Little Peter Ivanov likes to play knights. Or musketeers. Or samurai. It depends on his mood. For pa ...

  4. POJ2488A Knight's Journey[DFS]

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41936   Accepted: 14 ...

  5. LightOJ 1197 Help Hanzo(区间素数筛选)

    E - Help Hanzo Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  6. Knight Moves

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  7. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  8. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  9. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

随机推荐

  1. selenium 学习笔记 ---新手学习记录(4) 问题总结(java)-autoit3脚本使用

    1.安装autoit3 下载地址:点我下载 (提取码:9633) 提取码 下载完成后,一直下一步即可 2.上传头像使用脚本 代码如下: ControlFocus("打开",&quo ...

  2. C winpcap 网络抓包 并获取IP TCP 协议的相关信息

    以太网协议分析函数: void ethernet_protocol_packet_handle (u_char *argument, const struct pcap_pkthdr *packet_ ...

  3. LintCode-子数组之和

    题目描述: 给定一个整数数组,找到和为零的子数组.你的代码应该返回满足要求的子数组的起始位置和结束位置 样例 给出 [-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. publ ...

  4. ThinkPHP 3.1.2 模板中的变量

    一.变量输出 (重点) 1.标量输出 2.数组输出 {$name[1]} {$name['k2']} {$name.k1} 3.对象输出 {$name:k} {$name->k} 二.系统变量 ...

  5. android 之Fragment(官网资料翻译)

    原文地址: http://blog.csdn.net/lilu_leo/article/details/7671533 ***************************  正文分割线 ***** ...

  6. 在LINUX的命令提示符及CMD命令提示符中显示时间

    用途之一是可以查看某个命令或程序的执行时间. 一.CMD中显示时间设置 参数说明: $P:当前路径 $G:>(大于号) $T:当前时间,精确到0.01s 实验如下: C:\Users\g4-10 ...

  7. citrix协议ICA技术原理

    转载自: http://www.zrss.com.cn/article-110-1.html Citrix交付中心解决方式的核心是虚拟化技术,虚拟化计算的核心是ICA协议,ICA协议连接了执行在平台上 ...

  8. 提高你的Java代码质量吧:使用valueof前必须进行校验

    一.分析 每个枚举都是java.lang.Enum的子类,都可以访问Enum类提供的方法,比如hashCode.name.valueOf等,其中valueOf方法会把一个String类型的名称转变成枚 ...

  9. Android手机之间通过声音传输信息方法——声波通信(含project代码)

    大家可能都用过支付宝的声波支付.即两个终端同一时候打开该功能,一个终端作为发送端send,一个终端作为接收端get,send将本终端上发出的请求信息依照约定规则的算法进行声音编码,并播放出来,get端 ...

  10. zookeeper集群配置

    zookeeper集群网上demo一大堆,补充一下一些不明白的地方 1 复制2份zookeeper,savle作为备份节点 2.配置zoo.cfg # The number of millisecon ...