ACM(白银组题)hdu-2055

An easy problem
Time Limit: 1000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 33087
Accepted Submission(s): 21364

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

Author 8600 
Source   校庆杯Warm Up    
Recommend linle

题目简述:
这道题需要我们输入一个字母和一个数字,要求我们输出字母与数字的和。题目已经给出每个字母对应的数值。

题目分析:
定义两个数值,一个字符数组一个整型数组,字符数组接收输入的字母,整型数组来存入每个字母对应的值。数组下标一 一对应好,问题就简单很多了。

AC代码:

#include
using namespace std;
int main()
{
 char s[80],s1;
 int a[80], i, n,num;
 cin >> n;
 while (n--)
 {
  cin >> s1 >> num;
  int j = 0, k = 0;
  for (int i = 0; i < 52; i++ )
  {
   if (i % 2 == 0)
   {
    s[i] = ('a' + j);
    j++;
   }
   else
   {
    s[i] = ('A' + k);
    k++;
   }
  }  
   j = 0, k = 0;
  for (i = 0; i < 52; i++)
  {
   if (i % 2 == 0)
   {
    a[i] = -1 - j;
    j++;
   }
   else
   {
    a[i] = 1 + k;
    k++;
   }
  }
  for (i = 0; i < 52; i++)
  {
   if (s1 == s[i])
    break;
  }
  cout <<( a[i] + num) << endl;
 }
 return 0;
}

你可能感兴趣的:(ACM(白银组题)hdu-2055)