首页 > 其他 > 详细

An easy problem

时间:2014-10-29 01:55:08      阅读:240      评论:0      收藏:0      [点我收藏+]
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
 
 1 #include <stdio.h>   //A:65 Z:90 a:97 z:122
 2  
 3 int main(){
 4     int flag[123];
 5     int i;
 6     int j;
 7     int T;
 8     int number;
 9     char c;
10     
11     j=1;
12     for(i=65;i<=90;i++){
13         flag[i]=j;
14         j++;
15     }
16     
17     j=-1;
18     for(i=97;i<=122;i++){
19         flag[i]=j;
20         j--;
21     }
22     
23     scanf("%d",&T);
24     getchar();
25     
26     while(T--){
27         scanf("%c%d",&c,&number);
28         getchar();
29         
30         printf("%d\n",number+flag[c]);
31     }
32     
33     
34     
35         
36     return 0;
37 }

 

 

An easy problem

原文:http://www.cnblogs.com/zqxLonely/p/4058423.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!