An easy problem
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 33073 Accepted Submission(s): 21354
Problem Description
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).
Input
On the first line, contains a number T.then T lines follow, each line is a case.each case contains a letter and a number.
Output
for each case, you should the result of y+f(x) on a line.
Sample Input
6
R 1
P 2
G 3
r 1
p 2
g 3
Sample Output
19
18
10
-17
-14
-4
问题链接:HDU - 2055
问题简述:把A~ Z当做1~26,把a ~当做-1 ~-26,再加上一个数y,输出结果,多组输入输出。
问题分析:‘A’的ASCII码为65,将其减去64便可用‘A’代表1,同理,‘a’的ASCII码为97,将其减 去96并取负数便可用‘a’表示-1,其他的‘A’~‘Z’ ‘a’ ~‘z’也同理。将其值加上y值并输出即为所求值。
程序说明:i和n用于接下来输入输出的组数。ch代表字母,y代表要加的值。getchar()用于接收每次scanf后多余的字符‘\n’。
AC通过程序:
#include<stdio.h>
int main()
{
int i;
int n,y;
char c;
scanf("%d",&n);
getchar();
for(i=0;i<n;i++)
{
scanf("%c%d",&c,&y);
getchar();
if(c>='A'&&c<='Z')
{
printf("%d\n",y+c-64);
}else printf("%d\n",y-c+96);
}
return 0;
}