杭电 2055 An easy problem解决方法

杭电 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<stdio.h>
int main()
{
int a,s,i;
char z;
 while(scanf("%d",&a)!=EOF)
 {
  for(i=0;i<a;i++)
  {
     scanf("%c%d",&z,&s);
     if(z>='a'&&z<='z')
      printf("%d\n",-((int)(z-'a')+1)+s);
     else if(z>='A'&&z<='Z')
     printf("%d\n",(int)(z-'A')+1+s);
  }
 }
}
------解决方案--------------------

#include<stdio.h>
int main()
{
int a,s,i;
char z;
 while(scanf("%d",&a)!=EOF)
 {
  for(i=0;i<a;i++)
  {
z = getchar(); //scanf 输入 %c时 要考虑 上一次输入的换行符 还在输入流中。
     scanf("%c%d",&z,&s);
     if(z>='a'&&z<='z')
      printf("%d\n",-((int)(z-'a')+1)+s);
     else if(z>='A'&&z<='Z')
     printf("%d\n",(int)(z-'A')+1+s);
  }
 }
return 0; // 函数结束时 需要正常退出。
}


10080989 2014-02-10 09:35:22 Accepted 2055 0MS 228K 318 B