Parameter between a letter and a number 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 shoshould output the result of Y + f (x ).
-
Input
-
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 ).
-
Output
-
For each case, You shoshould the result of Y + f (x) on a line
-
Sample Input
-
6R 1P 2G 3r 1p 2g 3
-
Sample output
-
191810-17-14-4
-
Solution:
-
N groups of data are involved in this question, and each group of data starts with a character. scanf reads a line feed first, so you should use getchar to eat the carriage return before reading each line of data, no, only half of the data can be read.
-
Program code:
-
#include<stdio.h>int main(){int n,y,i;char x;scanf("%d",&n);while(n--){getchar();scanf("%c%d",&x,&y);if(x>='a'&&x<='z')printf("%d\n",'a'-x-1+y);else if(x>='A'&&x<='Z')printf("%d\n",x-'A'+1+y);}return 0;}
A letter and a number