hdu2055

这段代码是引用的,对scanf()运用比较熟练才行

#include <stdio.h>

int main()
{
 int n, a;
 char c;

 scanf("%d%*c", &n);
 while (n-- && scanf("%c%d%*c", &c, &a))
  printf("%d
", a + (c < 97 ? c - 'A' + 1 : 'a' - c - 1));

 return 0;
}

下面的是本人的,有点惭愧了

#include <stdio.h>
int main()
{
    int  nCase;
    int  y;
    char  ch;
    scanf("%d",&nCase);
    getchar();
    while(nCase--)
    {
        scanf("%c %d",&ch,&y);
        getchar();

        if(ch>='A'&&ch<='Z')
            printf("%d
",y+ch-'A'+1);
        else
            printf("%d
",y-(ch-'a'+1));
    }
    
    return 0;
}

此处为什么要加一个getchar(),这要好好研究scanf()函数才行


1. scanf()函数接收char时,空格,回车,tab此时均为有意义的字符了,不会被忽略。%d时会视为分隔
一般加上getchar()吸收/n
2. scanf("%s", str);此时不接收str中的空格,到空格就断了
如果想接收空格成一个字符串,则用如下:


scanf("%[^ ]",string); 

这里的意思是直到

每天早上叫醒你的不是闹钟,而是心中的梦~
原文地址:https://www.cnblogs.com/vintion/p/4117021.html