早教吧 育儿知识 作业答案 考试题库 百科 知识分享

杭电2055AneasyproblemProblemDescriptionwedefinef(A)=1,f(a)=-1,f(B)=2,f(b)=-2,...f(Z)=26,f(z)=-26;Giveyoualetterxandanumbery,youshouldoutputtheresultofy+f(x).InputOnthefirstline,containsanumberT.thenTlinesf

题目详情
杭电 2055 An easy problem
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
我的代码:这段一直过不了,检查不出错,无奈之下switch了一大串,终于通过了,不过还想求教这段到底哪里有问题,
#include
int main()
{
\x05int a,s,i;
\x05char z;
while(scanf("%d",&a)!=EOF)
{
\x05for(i=0;i='a'&&z='A'&&z
▼优质解答
答案和解析
这是我的ac码
我觉得可能是你的输入控制有问题吧,没有将换行符去掉
#include
int main()
{
int a,c;
char b;
scanf("%d",&a);
while(a--)
{
getchar();*********去掉换行符,有整数有有字符的时候要注意的.
b=getchar();
scanf("%d",&c);
if(b>='a') printf("%d\n",'a'-1-b+c);
else printf("%d\n",b-'A'+1+c);
}return 0;
}