码迷,mamicode.com
首页 > 其他好文 > 详细

An easy problem

时间:2014-10-29 01:56:59      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   for   sp   div   

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

标签:des   style   blog   io   color   ar   for   sp   div   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!