题目来自杭电
AC代码:
#include <stdio.h>
#include <string.h>
#include <cctype>
int change(char c)
{
if(isupper(c)) return c-'A'+1;//当参数c为大写英文字母(A-Z)时,返回非零值
if(islower(c)) return 'a'-c-1;//当参数c为小写英文字母(a-z)时,返回非零值
}
int main()
{
int a,n,num;
char c;
scanf("%d",&a);
while(a--)
{
scanf("%c %d",&c,&n);
getchar();//吸收回车符应放哪?-->备注1
num=change(c)+n;
printf("%d\n",num);
num=0;
}
return 0;
}
getchar()的作用:
清除缓冲区,即从缓冲区中读走一个字符。可用于吸收回车。
备注:
1.第一次WA:没有在scanf(“%c %d”,&c,&n);后getchar()
造成数字还储存在缓存区,赋错误输出