HDU_2055解题报告(JAVA)

来源:互联网 发布:淘宝官方下载 编辑:程序博客网 时间:2024/06/14 09:10

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


import java.util.*;public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int n = sc.nextInt();        for(int i=0;i<n;i++){            String a =  sc.next();            String b =  sc.next();            char a1 = a.charAt(0);            int b1 = Integer.valueOf(b);            if(65<=a1&&a1<=90){                System.out.println((b1+a1-64));            }            if(97<=a1&&a1<=122){                System.out.println((b1-a1+96));            }                           }    }}

在Java中,next()方法是不接收空格的,在接收到有效数据前,所有的空格或者tab键等输入被忽略,若有有效数据,则遇到这些键退出。

nextLine()可以接收空格或者tab键,其输入应该以enter键结束。

0 0
原创粉丝点击