Http://acm.pku.edu.cn/JudgeOnline/showcontest? Contest_id = 1345
Question A: Bit operations
Import java. util. collections;
Public class main {
Public static string trans (string [] S ){
Long L = long. parselong (s [0]. Trim (), 16 );
String B = long. tobinarystring (L );
// System. Out. println (B );
B = "00000000000000000000000000000000" + B;
B = B. substring (B. Length ()-32 );
// System. Out. println (B );
Char [] CH = B. tochararray ();
// System. Out. println (integer. parseint (string. valueof (s [1]. Trim ())));
Ch [B. Length ()-1-integer. parseint (string. valueof (s [1]. Trim ()] = '0 ';
Int I = integer. parseint (string. valueof (s [2]. Trim ()));
// System. Out. println (B. Length ());
Ch [B. Length ()-1-I] = '1 ';
Ch [B. Length ()-I] = '1 ';
Ch [B. Length () + 1-I] = '0 ';
String STR = new string (CH );
// System. Out. println (STR );
Long LL = long. parselong (STR, 2 );
Return long. tohexstring (LL );
}
Public static void main (string [] ARGs ){
Pipeline SC = new pipeline (system. In );
// While (SC. hasnextline ()){
String STR = SC. nextline ();
System. Out. println (main. Trans (Str. Split (",")));
//}
}
}
Question B: A simple replacement for deciphering passwords.
Import java. util. collections;
Public class main {
Private Static final string S1 = "abcdefghijklmnopqrstuvwxyz ";
Private Static final string S2 = "vwxyzabcdefghijklmnopqrstu ";
Public static void main (string [] ARGs ){
Pipeline SC = new pipeline (system. In );
While (SC. hasnextline ()){
String STR = SC. nextline ();
If (Str. Equals ("endofinput ")){
Break;
} Else if (! Str. Equals ("START ")&&! Str. Equals ("end ")){
Stringbuilder sb = new stringbuilder ();
Int Len = Str. Length ();
For (INT I = 0; I <Len; ++ I ){
Char c = Str. charat (I );
Int Index = s1.indexof (C );
If (index>-1 ){
Char CH = s2.charat (INDEX );
SB. append (CH );
} Else
SB. append (C );
}
System. Out. println (sb. tostring ());
}
}
}
}
C: questions about data reporting for children (hehe)
Import Java. util. using list; <br/> Import Java. util. values; </P> <p> public class main {</P> <p> Public static void sloves (values list <string> childlist, int W, int S) {<br/> int sum = childlist. size (); </P> <p> while (sum> 0) {<br/> int Index = (W + s-1-1) % sum; <br/> W = index + 1; <br/> // system. out. println ("Index =" + index); <br/> system. out. println (childlist. get (INDEX); <br/> childlist. rem Ove (INDEX); <br/> -- sum; <br/> If (W> sum) <br/> W = 0; <br/>}</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> transport SC = new partition (system. in); <br/> int testnum = SC. nextint (); <br/> shortlist <string> CH = new shortlist <string> (); <br/> SC. nextline (); <br/> for (INT I = 0; I <testnum; ++ I) {<br/> CH. add (SC. nextline (); <br/> // System. Out. println (ch. get (I); <br/>}< br/> // SC. nextline (); <br/> string S = SC. nextline (); <br/> string [] Ss = S. split (","); <br/> sloves (CH, integer. parseint (ss [0]), integer. parseint (ss [1]); <br/>}</P> <p >}< br/> D: time and date format conversion: Notes: note: 00: 00: 00 is 12:00:00 </P> <p> Import Java. util. break; </P> <p> public class main {</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (strin G [] ARGs) {</P> <p> limit SC = new limit (system. in); <br/> int testnum = SC. nextint (); <br/> SC. nextline (); <br/> for (INT I = 0; I <testnum; ++ I) {<br/> string STR = SC. nextline (); <br/> int index1 = Str. indexof ("/"); <br/> int index2 = Str. indexof ("-"); <br/> string S1 = Str. substring (index1 + 1, index2); <br/> S1 = S1 + "/" + Str. substring (0, index1); <br/> string S2 = Str. substring (index2 + 1); <br/> string HH = s2.substring (0, s2.indexof (":"); <br/> int H = integer. parseint (s2.substring (0, s2.indexof (":"); <br/> If (H <12 & H> 0) <br/> system. out. println (S1 + "-" + S2 + "am"); <br/> else if (H = 0) <br/> system. out. println (S1 + "-" + s2.replace ("00", "12") + "am"); <br/> else {<br/> If (H! = 12) <br/> H = H-12; <br/> string temp = "00" + H; <br/> temp = temp. substring (temp. length ()-2); <br/> system. out. println (S1 + "-" + s2.replace (HH, temp) + "PM"); <br/>}< br/> // system. out. println (h); <br/>}</P> <p >}< br/>
Question E: letter rotation games (Simple simulation questions)
Import Java. util. extends; </P> <p> public class main {</P> <p> Private Static int sum = 0; <br/> Private Static int r = 0; <br/> Private Static int C = 0; <br/> Private Static int flag1 = 0; <br/> Private Static int flag2 = 0; <br/> Private Static char cc = 'a'; <br/> Private Static int leftcol = 0; <br/> Private Static int rightcol = 0; <br/> Private Static int toprow = 0; <br/> Private Static int bottomrow = 0; </P> <p> Public static void sloves (char [] [] CH, int N, int m) {<br/> // system. out. println (sum + "," + R + "," + C + "," + flag1 + "," + <br/> // flag2 ); </P> <p> If (flag1 = 0) {<br/> If (flag2 = 0) {<br/> while (C <= rightcol) {<br/> CH [r] [c] = cc; <br/> If (Cc = 'Z') <br/> cc = 'a '; <br/> else <br/> cc = (char) (CC + 1); <br/> C ++; <br/> ++ sum; <br/>}< br/> C --; <br/> r ++; <br/> flag1 = 1; <br/> flag2 = 0; <br/> toprow ++; <br/> // sloves (CH, R, C-1, 1, 0, n, m, CC ); <br/>} else {<br/> while (C> = leftcol) {<br/> CH [r] [c] = cc; <br/> If (Cc = 'Z') <br/> cc = 'a'; <br/> else <br/> cc = (char) (CC + 1); <br/> C --; <br/> ++ sum; <br/>}< br/> C ++; <br/> flag1 = 1; <br/> flag2 = 1; <br/> r --; <br/> bottomrow --; <br/> // sloves (CH, r, C + 1, 1, 1, n, m, CC); <br/>}< br/>}else {<br/> If (flag2 = 0) {<br/> while (r <= bottomrow) {<br/> CH [r] [c] = cc; <br/> If (Cc = 'Z ') <br/> cc = 'a'; <br/> else <br/> cc = (char) (CC + 1); <br/> ++ R; <br/> ++ sum; <br/>}< br/> r --; <br/> flag1 = 0; <br/> flag2 = 1; <br/> C --; <br/> rightcol --; <br/> // sloves (CH, R-1, C, 0, 1, n, m, CC); <br/>}else {<br/> while (r >=toprow) {<br/> CH [r] [c] = cc; <br/> If (Cc = 'Z') <br/> cc = 'a'; <br/> else <br/> cc = (char) (CC + 1); <br/> r --; <br/> ++ sum; <br/>}< br/> r ++; <br/> flag1 = flag2 = 0; <br/> C ++; <br/> leftcol ++; <br/> // sloves (CH, R + 1, c, 0, 0, n, m, CC ); <br/>}</P> <p> Public static void main (string [] ARGs) {<br/> transport SC = new partition (system. in); </P> <p> while (SC. hasnextint () {</P> <p> int M = SC. nextint (); <br/> int n = SC. nextint (); <br/> char [] [] CH = new char [m] [N]; <br/> // For (INT I = 0; I <m; ++ I) <br/> // arrays. fill (CH [I], '0 '); <br/>/********** initialize the global variable ***********/<br/> cc = 'a '; <br/> sum = 0; <br/> r = 0; <br/> C = 0; <br/> flag1 = 0; <br/> flag2 = 0; <br/> leftcol = 0; <br/> rightcol = n-1; <br/> toprow = 0; <br/> bottomrow = m-1; <br/>/******* s ********/<br/> int num = N * m; <br/> while (sum <num) <br/> sloves (CH, n, m); <br/> for (INT I = 0; I <m; I ++) {<br/> system. out. print (""); <br/> for (Int J = 0; j <n-1; j ++) {<br/> system. out. print (CH [I] [J] + ""); <br/>}< br/> system. out. print (CH [I] [n-1]); <br/> system. out. println (); <br/>}</P> <p>
Note: questions about the ACM training team of Chengdu University