首页 > ACM题库 > HDU-杭电 > hdu 2055 An easy problem[解题报告]C++
2013
12-26

hdu 2055 An easy problem[解题报告]C++

An easy problem

问题描述 :

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).

输入:

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.

输出:

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.

样例输入:

6
R 1
P 2
G 3
r 1
p 2
g 3

样例输出:

19
18
10
-17
-14
-4

2011-12-15 02:03:44

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2055

题意:字母替换成数字,求和,简单~~

代码:

# include <stdio.h>
# include <math.h>


int main ()
{
    int T, num ;
    char ch ;
    scanf ("%d%*c", &T) ;
    while (T--)
    {
        scanf ("%c %d%*c", &ch, &num) ;
        if (ch >= 'a' && ch <= 'z')
            num -= (ch-'a'+1) ;
        else
            num += (ch-'A'+1) ;
        printf ("%d\n", num) ;
    }
    return 0 ;
}

解题转自:http://www.cnblogs.com/lzsz1212/archive/2012/01/06/2314613.html


  1. 算法是程序的灵魂,算法分简单和复杂,如果不搞大数据类,程序员了解一下简单点的算法也是可以的,但是会算法的一定要会编程才行,程序员不一定要会算法,利于自己项目需要的可以简单了解。

  2. 您没有考虑 树的根节点是负数的情况, 若树的根节点是个很大的负数,那么就要考虑过不过另外一边子树了