杭电 2055 An easy problemProblem 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 should output the result of y+f(x).InputOn the first line,contains a number T.then T lines f
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/02 04:30:27
![杭电 2055 An easy problemProblem 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 should output the result of y+f(x).InputOn the first line,contains a number T.then T lines f](/uploads/image/z/14598261-45-1.jpg?t=%E6%9D%AD%E7%94%B5+2055+An+easy+problemProblem+Descriptionwe+define+f%28A%29+%3D+1%2Cf%28a%29+%3D+-1%2Cf%28B%29+%3D+2%2Cf%28b%29+%3D+-2%2C...f%28Z%29+%3D+26%2Cf%28z%29+%3D+-26%3BGive+you+a+letter+x+and+a+number+y+%2Cyou+should+output+the+result+of+y%2Bf%28x%29.InputOn+the+first+line%2Ccontains+a+number+T.then+T+lines+f)
杭电 2055 An easy problemProblem 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 should output the result of y+f(x).InputOn the first line,contains a number T.then T lines f
杭电 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
杭电 2055 An easy problemProblem 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 should output the result of y+f(x).InputOn the first line,contains a number T.then T lines f
这是我的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;
}