217-a letter and a number
内存限制:64MB
时间限制:3000ms
特判: No
通过数:4
提交数:5
难度:1
题目描述:
we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;
Give you a letter x and a number y , you should output the result of y+f(x).
Give you a letter x and a number y , you should output the result of y+f(x).
输入描述:
On the first line, contains a number T(0<T<=10000).then T lines follow, each line is a case.each case contains a letter x and a number y(0<=y<1000).
输出描述:
for each case, you should the result of y+f(x) on a line
样例输入:
6 R 1 P 2 G 3 r 1 p 2 g 3
样例输出:
19 18 10 -17 -14 -4
C/C++ AC:
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <cmath> 6 #include <stack> 7 #include <set> 8 #include <map> 9 #include <queue> 10 #include <climits> 11 #define PI 3.1415926 12 13 using namespace std; 14 int n; 15 16 int main() 17 { 18 cin >>n; 19 while (n --) 20 { 21 char letter; 22 int number; 23 cin >>letter >>number; 24 if (letter >= 'A' && letter <= 'Z') 25 { 26 cout <<letter - 'A' + 1 + number <<endl; 27 } 28 else 29 { 30 cout <<-1 * (letter - 'a' + 1) + number <<endl; 31 } 32 } 33 }