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. Python 城市菜单详解(超详解)

      print("--------城市查询系统---------") print("--------按数值进行查询--------") menu={" ...

  2. [LeetCode]题解:005-Longest Palindromic Substring优化

    题目来源和题意分析: 详情请看我的博客:http://www.cnblogs.com/chruny/p/4791078.html 题目思路: 我上一篇博客解决这个问题的时间复杂度是最坏情况是(O(n^ ...

  3. ios 学习笔记(8) 控件 按钮(UIButton)的使用方法

    在实际开发中,对于开发者来说,更多的还是使用“自定义”按钮.将“按钮”对象的类型设置成UIButtonTypeCustom.这样一来,按钮的所有元素都将由开发者来配置和自定义. 对于一个自定义按钮来说 ...

  4. libcprops

    Install Howto Download the latest epel-release rpm from http://dl.fedoraproject.org/pub/epel/6/x86_6 ...

  5. javascript closure 闭包 事件绑定

    先来一个基本的例子 <!-- 实现一段脚本,使得点击对应链接alert出相应的编号 --> <meta http-equiv="Content-Type" con ...

  6. QTP 9.2 下载&破解

    版本不同 但是破解总是这个 crack文件下载 http://ishare.iask.sina.com.cn/f/13802744.html   QTP9.2 下载地址 http://www.duot ...

  7. poj 2051 Argus(优先队列)

    题目链接: http://poj.org/problem?id=2051 思路分析: 优先级问题,使用优先队列求解:当执行某个任务后,再增加一个任务到队列中, 该任务的优先级为执行任务的时间加上其时间 ...

  8. [置顶] js综合应用:表格的四则运算

    在做调查问卷的过程中,遇到一个表格的统计问题,算是需要些js方面的综合知识,所以记录下来. 在上次完成了基本的求和的基础上,添加了基本的加减乘除四则运算. 基本需求简化后如下: 对应的htm了为: & ...

  9. rebol高速入门

    看了Java夜未眠之后,我也有点想学习其它语言了,希望能够完毕Python在写GUI程序和Web的程序的缺陷,写GUI程序比較看好VB,写Web程序看好PHP,不过首先想玩玩rebol. 翻译的Reb ...

  10. 基于hash的文档判重——simhash

    本文环境: python3.5 ubuntu 16.04 第三方库: jieba 文件寄于github: https://github.com/w392807287/angelo_tools.git ...