早教吧作业答案频道 -->其他-->
杭电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
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;
}
我觉得可能是你的输入控制有问题吧,没有将换行符去掉
#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;
}
看了 杭电2055Aneasypr...的网友还看了以下:
在传统的集合运算中,关系R和关系S的差的结果可表示为(t表示元组)()。A.{tlt∈R∨t∈S)B 2020-05-23 …
(35)设关系 R,S 和T 分别如下图所示。则有T A)T= R ? S B)T= R ? SC) 2020-05-23 …
设关系R与关系S具有相同的目,且相对应的属性的值取自同一个域,则R∩S可记作A.{tlt∈R∨t∈S 2020-05-24 …
A.πA,D(σC=D(R×S))B.πA,R,D(σS,C=R,D/(R×S))C.πA,R,D( 2020-05-26 …
A.πA,D(σC=D(R×S))B.πA,R.D(σR.C=S.D(R×S))C.πA,R.D(σ 2020-05-26 …
A.πA,B,C (σB=B(R×S))B.πR.A,R.B,R.C (σR.B=S.B (R×S) 2020-05-26 …
(20)A.R.B = S.B AND R.C = S.C AND R.C < S.BB.R.B = 2020-05-26 …
WHERE (54);A.R.B= S.B AND R.C = S.C AND R.C 2020-05-26 …
下列式子中,不正确的是______。A.R-S=R-(R∩S)B.R=(R-S)∪(R∩S)C.R∩ 2020-05-26 …
A.πA,D(σC=D(R×S))B.πA,R.D(σS.C=R.D(R×S))C.πA,R.D(σ 2020-05-26 …