小景哥哥网站:[打开连接]
(http://www.jasonjing.cn/home.action)
1014. 福尔摩斯的约会 (20)
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧!3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母’D’,代表星期四;第2对相同的字符是’E’,那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母’s’出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。
输入格式:
输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。
输出格式:
在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
输入样例:
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
输出样例:
THU 14:04
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String one = br.readLine(),two = br.readLine(),three = br.readLine(),four = br.readLine();
boolean isDay = false;
boolean isHour = false;
for (int i = 0; i < one.length() && i < two.length(); i++) {
char c = one.charAt(i);
if (c == two.charAt(i)) {
if (isDay && !isHour && ((c >= 'A' && c <= 'N') || Character.isDigit(c))) {
isHour = true;
if (c >= '0' && c <= '9') {
System.out.print("0" + c);
} else {
System.out.print(c - 'A' + 10);
}
}
if (!isDay && c >= 'A' && c <= 'G') {
isDay = true;
switch (one.charAt(i)) {
case 'A':
System.out.print("MON ");
break;
case 'B':
System.out.print("TUE ");
break;
case 'C':
System.out.print("WED ");
break;
case 'D':
System.out.print("THU ");
break;
case 'E':
System.out.print("FRI ");
break;
case 'F':
System.out.print("SAT ");
break;
case 'G':
System.out.print("SUN ");
break;
}
}
}
}
for (int i = 0; i < three.length() && i < four.length(); i++) {
char c = three.charAt(i);
if (c == four.charAt(i) && (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z')) {
System.out.printf(":%02d", i);
}
}
}
}