http://acm.pku.edu.cn/JudgeOnline/showcontest?contest_id=1345
A题:位操作
import java.util.Scanner;
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) {
Scanner sc = new Scanner(System.in);
// while (sc.hasNextLine()) {
String str = sc.nextLine();
System.out.println(Main.trans(str.split(",")));
// }
}
}
B题:破译密码 简单的置换,对着密码表
import java.util.Scanner;
public class Main {
private static final String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String s2 = "VWXYZABCDEFGHIJKLMNOPQRSTU";
public static void main(String[] args) {
Scanner sc = new Scanner(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题:小孩报数问题 c语言书课后习题(赫赫)
E题:字母旋转游戏(简单的模拟题)
注:成都大学ACM集训队训练题目