1 题目
2 代码
import java.util.Scanner;
public class A1061 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String oneStr = sc.next();
String twoStr = sc.next();
String threeStr = sc.next();
String fourStr = sc.next();
String[] Day = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
String[] HH = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"};
int l1 = oneStr.length() > twoStr.length() ? twoStr.length() : oneStr.length();
int l2 = threeStr.length() > fourStr.length() ? fourStr.length() : threeStr.length();
int num = 0;
String res = "";
for (int i = 0; i < l1; i++) {
if (oneStr.charAt(i) == twoStr.charAt(i) && oneStr.charAt(i) >= 'A' && oneStr.charAt(i) <= 'G') {
res = res + Day[oneStr.charAt(i) - 'A'] + " ";
num = i;
break;
}
}
for (int i = num + 1; i < l1; i++) {
if (oneStr.charAt(i) == twoStr.charAt(i)) {
if (oneStr.charAt(i) >= '0' && oneStr.charAt(i) <= '9') {
res += HH[oneStr.charAt(i) - '0'] + ":";
break;
}
if (oneStr.charAt(i) >= 'A' && oneStr.charAt(i) <= 'N') {
res += HH[oneStr.charAt(i) - 55] + ":";
break;
}
}
}
for (int i = 0; i < l2; i++) {
if (threeStr.charAt(i) == fourStr.charAt(i) && (threeStr.charAt(i) >= 'A' && threeStr.charAt(i) <= 'Z' || threeStr.charAt(i) >= 'a' && threeStr.charAt(i) <= 'z')) {
res += String.format("%02d", i);
break;
}
}
System.out.print(res);
}
}
3 要点
(1)看清规律,首先扫描前两个字符串,寻找第一对相同位置的A~G的大写字母。
(2)然后继续往后扫描,碰到第一对相同位置的0~9或A~N的字符。
(3)最后扫描后两个字符串,寻找第一对相同位置的A~Z或a~z的英文字母。