input | output |
---|---|
3 a1 d4 g6 |
2 8 6 |
// 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 = 0; if((i - 1) >= 1) { if((j - 2) >= 1) count++; if((j + 2) <= 8) count++; } if((i - 2) >= 1) { if((j - 1) >= 1) count++; if((j + 1) <= 8) count++; } if((i + 1) <= 8) { if((j - 2) >= 1) count++; if((j + 2) <= 8) count++; } if((i + 2) <= 8) { if((j - 1) >= 1) count++; if((j + 1) <= 8) 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‘ + 1, n)); } } int main() { solve(); return 0; }
原文:http://www.cnblogs.com/acutus/p/3518791.html