HDU 2055 An easy problem (Java)

Source: Internet
Author: User

Problem:

Started trying to do array elements with characters, but it doesn't work. A Z is discharged when judging the statement.


An easy problemTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16516 Accepted Submission (s): 11096


Problem descriptionwe define f (a) = 1, f (a) =-1, f (b) = 2, f (b) =-2, ... f (z) = n, f (z) =-26;
Give you a letter x and a number y, you should output the result of y+f (x).
Inputon The first line, contains a number t.then T lines follow, each line was a Case.each case contains a letter and a num ber.
Outputfor the should the result of y+f (x) on a line.
Sample Input
6R 1P 2G 3r 1p 2g 3

Sample Output
191810-17-14

Code:

Import java.util.*;p ublic class main{public static void M1 (char str,int kk) {char aa[]={' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z '};for (int i=0;i<26;i++) {if (aa[i]==str ) System.out.println ((i+1) +kk);}} public static void M2 (char str,int kk) {char aa[]={' a ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' x ', ' y ', ' z '};for (int i=0;i<26;i++) {if (AA[I]==STR) System.out.println (-(i+1) +KK);}} public static void Main (string[] args) {Scanner cin=new Scanner (system.in), int nn=cin.nextint (); for (int ii=0;ii<nn; ii++) {String st=cin.next (); int kk=cin.nextint (); Char A[]=st.tochararray (); Char str=a[0];if (str>= ' a ' && Str<= ' z ') M2 (STR,KK); else if (str>= ' A ' &&str<= ' z ') M1 (STR,KK);}}


HDU 2055 An easy problem (Java)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.