大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 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
1
2
3
4
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
输出样例:
THU 14:04
1
THU14:04
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String one = in.nextLine();
String two = in.nextLine();
String three = in.nextLine();
String four = in.nextLine();
in.close();
boolean isDay = false;
boolean isHour = false;
for (int i = 0; i < one.length() && i < two.length(); i++) {
if (one.charAt(i) == two.charAt(i)) {
if (((one.charAt(i) >= 'A' && one.charAt(i) <= 'N') || Character.isDigit(one.charAt(i))) && !isHour
&& isDay) {
isHour = true;
if (one.charAt(i) >= '0' && one.charAt(i) <= '9') {
System.out.print("0" + one.charAt(i));
} else {
System.out.print(one.charAt(i) - 'A' + 10);
}
}
if (one.charAt(i) >= 'A' && one.charAt(i) <= 'G' && !isDay) {
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++) {
if ((Character.isUpperCase(three.charAt(i)) || Character.isLowerCase(three.charAt(i)))
&& three.charAt(i) == four.charAt(i)) {
System.out.printf(":%02d", i);
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
importjava.util.Scanner;
publicclassMain{
publicstaticvoidmain(String[]args){
Scannerin=newScanner(System.in);
Stringone=in.nextLine();
Stringtwo=in.nextLine();
Stringthree=in.nextLine();
Stringfour=in.nextLine();
in.close();
booleanisDay=false;
booleanisHour=false;
for(inti=0;i
if(one.charAt(i)==two.charAt(i)){
if(((one.charAt(i)>='A'&&one.charAt(i)<='N')||Character.isDigit(one.charAt(i)))&&!isHour
&&isDay){
isHour=true;
if(one.charAt(i)>='0'&&one.charAt(i)<='9'){
System.out.print("0"+one.charAt(i));
}else{
System.out.print(one.charAt(i)-'A'+10);
}
}
if(one.charAt(i)>='A'&&one.charAt(i)<='G'&&!isDay){
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(inti=0;i
if((Character.isUpperCase(three.charAt(i))||Character.isLowerCase(three.charAt(i)))
&&three.charAt(i)==four.charAt(i)){
System.out.printf(":%02d",i);
}
}
}
}