PAT-1014. 福尔摩斯的约会 (20)

来源:互联网 发布:mysql 指定ip配置 编辑:程序博客网 时间:2024/04/30 09:42

大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 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
这道题挺简单的,有一个现成的函数判断是不是字母  Character.isLetter(char i) 可以用上,但我之前不知道。


import java.util.Scanner;public class Main {public static void main(String[] args){Scanner in=new Scanner(System.in);while(in.hasNext()){String str1 = in.nextLine();String str2 = in.nextLine();String str3 = in.nextLine();String str4 = in.nextLine();int cnt1 =1;int cnt2=0;String day="";String hour="0";String fen="";int len1 = Math.min(str1.length(), str2.length());int len2 = Math.min(str3.length(), str4.length());for(int i = 0; i<len1; i++){if(cnt1==1&&str1.charAt(i)==str2.charAt(i) &&(str2.charAt(i)>='A' && str2.charAt(i)<='Z')){switch (str2.charAt(i)){case 'A': day="MON";cnt1++;break;case 'B': day="TUE";cnt1++;break;case 'C': day="WED";cnt1++;break;case 'D': day="THU";cnt1++;break;case 'E': day="FRI";cnt1++;break;case 'F': day="SAT";cnt1++;break;case 'G': day="SUN";cnt1++;break;}continue;}if(cnt1 ==2 &&str1.charAt(i)==str2.charAt(i) &&((str2.charAt(i)>='A' && str2.charAt(i)<='N') || (str2.charAt(i)>='0' && str2.charAt(i)<='9'))){switch (str2.charAt(i)){case '0': hour="00";break;case '1': hour="01";break;case '2': hour="02";break;case '3': hour="03";break;case '4': hour="04";break;case '5': hour="05";break;case '6': hour="06";break;case '7': hour="07";break;case '8': hour="08";break;case '9': hour="09";break;case 'A': hour="10";break;case 'B': hour="11";break;case 'C': hour="12";break;case 'D': hour="13";break;case 'E': hour="14";break;case 'F': hour="15";break;case 'G': hour="16";break;case 'H': hour="17";break;case 'I': hour="18";break;case 'J': hour="19";break;case 'K': hour="20";break;case 'L': hour="21";break;case 'M': hour="22";break;case 'N': hour="23";break;}break;}}for(int j =0;j<len2;j++){if(str3.charAt(j)==str4.charAt(j) &&((str3.charAt(j)>='A' && str3.charAt(j)<='Z') ||(str3.charAt(j)>='a' && str3.charAt(j)<='z'))){if(cnt2<10)fen="0"+cnt2;elsefen=""+cnt2;break;}cnt2++;}System.out.println(day+" "+hour+":"+fen);}}}




0 0
原创粉丝点击