An easy problem HDU - 2055(對char和int的理解;Xcode中字符輸入分輸入法)

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

 

本題還是坑在 對於 char 和 int 的理解上 還有 對於scanf("%c",&a); 會吸收 換行符和空格的 認識沒有到位。
還有剩餘的一個疑問 就是對a 進行如下操作時的會導致錯誤產生的不理解 a=(a-96)*-1+b; 第一個測試對 第二個就不行了。

大寫字母和小寫字母在字母表中的位置

        if(a>='A'&&a<='Z')

            printf("%d\n",a-'A'+1+b);

        if(a>='a'&&a<='z')

            printf("%d\n",(a-96)*-1+b);

另外,Xcode中字母無論大小寫輸入最後保存的都是大寫·········(哭暈在廁所!!!)

下午找到原因:因爲是拼音輸入法,按下caps lock在輸入英文,在xcode中這是不行的,切換成英文輸入法就好了


#include <iostream>
#include <cstdio>
#include "cctype"
#include "cstring"
#include "algorithm"
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>//Hash_map:因爲標準化的推進,hash_map屬於非標準容器,未來將要用:boost中tr1中的unordered_map替代之
using namespace std;
const int Maxn=1000;

int main(int argc, const char * argv[]) {
    char a;
    int n,b;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        scanf("%c",&a);
        getchar();
        scanf("%d",&b);
        getchar();
        if(a>='A'&&a<='Z')
            printf("%d\n",a-'A'+1+b);
        if(a>='a'&&a<='z')
            printf("%d\n",(a-96)*-1+b);
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章