Problem descriptionwe 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 shoshould output the result of Y + f (x ). inputon the first line, contains a number t. then T lines follow, each line is a case. each case contains a letter and a number. outputfor each case, You shoshould the result of Y + f (x) on a line. sample input6r 1 P 2G 3R 1 P 2G 3 sample output19 1810-17-14-4
1 #include <stdio.h> //A:65 Z:90 a:97 z:122 2 3 int main(){ 4 int flag[123]; 5 int i; 6 int j; 7 int T; 8 int number; 9 char c;10 11 j=1;12 for(i=65;i<=90;i++){13 flag[i]=j;14 j++;15 }16 17 j=-1;18 for(i=97;i<=122;i++){19 flag[i]=j;20 j--;21 }22 23 scanf("%d",&T);24 getchar();25 26 while(T--){27 scanf("%c%d",&c,&number);28 getchar();29 30 printf("%d\n",number+flag[c]);31 }32 33 34 35 36 return 0;37 }
An easy problem