HDOJ 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

题意: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)..

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String lowerCase = "0abcdefghijklmnopqrstuvwxyz";
        String capital = "1ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int n =sc.nextInt();
        //sc.next();
        while(n-->0){
            String strs = sc.next();
            //System.out.println(strs);
            int y = sc.nextInt();
            char x = strs.charAt(0);
            //strs = strs.substring(2);
            //int y = Integer.parseInt(strs,10);

            //System.out.println(x);
            //System.out.println(y);
            int g=0,h=0;
            for(int i=1;i<lowerCase.length();i++){
                if(x==lowerCase.charAt(i)){
                    g=-i;
                    break;
                }
            }
            for(int i=1;i<capital.length();i++){
                if(x==capital.charAt(i)){
                    h=i;
                    break;
                }
            }
            System.out.println(y+g+h);

        }

    }

}
时间: 2024-09-20 10:37:36

HDOJ 2055 An easy problem的相关文章

HDOJ(HDU) 2132 An easy problem

Problem Description We once did a lot of recursional problem . I think some of them is easy for you and some if hard for you. Now there is a very easy problem . I think you can AC it. We can define sum(n) as follow: if i can be divided exactly by 3 s

HDOJ(HDU) 2123 An easy problem(简单题...)

Problem Description In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j. Input The first line of input is an integer C which indicate the

HDOJ 1040 As Easy As A+B

Problem Description These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights. Give you some integers, your task is to sort these numbe

HDOJ 1048 The Hardest Problem Ever(加密解密类)

Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sou

HDOJ/HDU 1022 Train Problem I(模拟栈)

Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes

HDOJ 1002 A + B Problem II

Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines fol

HDOJ 1076 An Easy Task(闰年计算)

Problem Description Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him? Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap y

HDOJ 2058 The sum problem

Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M. Input Input contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).i

HDOJ 2101 A + B Problem Too

Problem Description This problem is also a A + B problem,but it has a little difference,you should determine does (a+b) could be divided with 86.For example ,if (A+B)=98,you should output no for result. Input Each line will contain two integers A and