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安装集成包

    anaconda, 包含各种科学运算包以及astropy.装完它一劳永逸. https://www.continuum.io/downloads

  2. Android UiAutomator 自动化测试环境搭建---新手1

    1.首先需要准备的工具有 1.java jdk 2. android开发工具 adt 3.ant 安装包(如果下载adt里面有) 2.首先安装java环境,jdk这个百度就可以了. 3.android ...

  3. Oracle中SQL语句学习五(统计分组语句group by和having)

    oracle(41) 在 应用系统开发中,进行需要统计数据库中的数据,当执行数据统计时,需要将表中的数据进行分组显示,在统计分组中是通过group by子句.分组函数.having子句共同实现的.其中 ...

  4. 【零基础学习iOS开发】【01-前言】01-开篇

    本文目录 一.什么是iOS 二.主流手机操作系统 三.什么是iOS开发 四.学习iOS开发的目的 五.学习iOS开发的前提 从今天开始,我就开始更新[零基础学习iOS开发]这个专题.不管你是否涉足过I ...

  5. STL deque详解

    英文原文:http://www.codeproject.com/Articles/5425/An-In-Depth-Study-of-the-STL-Deque-Container 绪言 这篇文章深入 ...

  6. 如何调试MFC中的内存泄漏

    转载地址:http://www.cnitblog.com/martin/archive/2006/04/21/9460.html 首先,应该是MFC报告我们发现内存泄漏.注意:要多运行几次,以确定输出 ...

  7. CERC 2013 Magical GCD

    题目大意如下:给定一个序列,每个序列有值xi,现给定t个数列,对于每个长n的数列,求一段[l,r]使 [r-l+1]*gcd(l,r)最大,gcd(l,r)指的是该连续区间的最大公约数. 不难想到n^ ...

  8. qwebkit - Open new window after click using QT - Stack Overflow

    qwebkit - Open new window after click using QT - Stack Overflow Open new window after click using QT

  9. HA for openstack

    mysql ha instance ha openstack博客:http://blog.csdn.net/tantexian/article/list/2 使用eclipse远程调试openstac ...

  10. Ext JS学习第十天 Ext基础之动态加载JS文件(补充)

    此文用来记录学习笔记: •Ext4.x版本提供的一大亮点就是Ext.Loader这个类的动态加载机制!只要遵循路径规范,即可动态加载js文件,方便把自己扩展组件动态加载进来,并且减轻浏览器的压力. • ...