pat乙级 1014 java_PAT 乙级 1014. 福尔摩斯的约会 (20) Java版

大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 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);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值