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).
6 R 1 P 2 G 3 r 1 p 2 g 3
19 18 10 -17 -14 -4
这道题是一道很简单的题,因为a~b A~B都有各自的ASCII码,只需要经过一定的加减操作便可以实现目的,比如A代表的数字是1,则给A-64便是想要的答案,然后转化成int就行,代码如下:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
getchar();
while(n--)
{
int num;
char c;
scanf("%c %d",&c,&num);
getchar();
if(c>='a'&&c<='z')
printf("%d\n",num-(int)(c-'a'+1));
else
printf("%d\n",num+(int)(c-'A'+1));
}
return 0;
}