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)