早教吧作业答案频道 -->其他-->
杭电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...的网友还看了以下:
1.若O(20°N,90°E)为太阳直射点,弧线EP、FP分别为晨线和昏线的一段,则 ( ) A. 2020-05-17 …
在公式E=I(R+r/n)中,已知E,I,R,r,求E≠IR,求n在公式E=I(R+r/n)中,已 2020-05-23 …
英语单词填空1.时间状语:d-r-n-2.场所:b-s-s-o-f-r--e-a-t-e-t3.教 2020-07-14 …
设E表示由n阶单位矩阵第i行与第j行互换得到的初等矩阵,则,E(I,J)^2=.设E表示由n阶单位 2020-07-16 …
怎么用e^(iθ)和e^(-iθ)来表达cosθ?cosθ=e^(iθ)-isinθ.然后就卡住了 2020-07-21 …
设g(x)=px-q/x-2f(x),其中f(x)=lnx,且g(e)=qe-p/e-2.(e为自 2020-08-02 …
求证e^i(4π/n)+e^i(8π/n)+...+e^i4(n-1)π/n+e^i(4nπ/n)= 2020-11-01 …
请问英文人名后的P.E.,DEE中的DEE是什么意思?请问英文人名后的P.E.,如JOSEPHA.S 2020-11-05 …
二阶微分方程求解题目2xy''=y'令p=y',则y''=p'=>2xp'=p=>2*dp/p=dx 2020-11-16 …
英语向高人求教!写几句话.每句开头的第一个字母分别是“L,i,U,F,E,i,F,E,i,w,o,a 2020-12-15 …