Sherlock Holmes received A strange note: let's date 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. The detective soon understood that the strange garbled code on the note was actually the date time at 14:04 on Thursday, because the first pair of the same capital letters (case sensitive) in the first two strings was the fourth letter D, representing Thursday; the second pair of the same characters were E, which was the fifth English letter, representing the 14th hour of the day (so 0 of the day Points to 23 are represented by the numbers 0 to 9, and the capital letters A to N); the first pair of the following two strings of the same English letter S appears in the fourth position (counting from 0), representing the fourth minute. Now given two pairs of strings, please help Sherlock Holmes decode the date time.
Input format:
The input gives four non empty, non blank, and no longer than 60 strings in four lines.
Output format:
Output the appointment time in a row in the format of DAY HH:MM, where DAY is the three character abbreviation of a week, that is, MON for Monday, TUE for Tuesday, WED for Wednesday, THU for Thursday, FRI for Friday, SAT for Saturday, SUN for Sunday. Question input ensures that each test has a unique solution.
Input example:
==3485djDkxh4hhGE ==
==2984akDfkkkkggEdsb ==
==s&hgsfdk ==
d&Hyscvnm
Output example:
THU 14:04
My idea: this question seems simple, but we need to understand each condition. Note that the day of the week is determined by the first capital letter of the previous two strings, and the capital letter must be between A and G. it's not difficult for the last two strings
import java.util.*; public class Main{ final static String[]weekdays={"MON","TUE","WED","THU","FRI","SAT","SUN"}; public static void main(String []args){ Scanner sc=new Scanner(System.in); String weekday=""; int hour=0; int minute=0; String s1=sc.next(); String s2=sc.next(); char[]cs1=s1.toCharArray(); char[]cs2=s2.toCharArray(); int len1=Math.min(s1.length(),s2.length()); boolean flag=false; for(int i=0;i<len1;++i){ if(!flag){ if(Character.isUpperCase(cs1[i])&&Character.isUpperCase(cs2[i])&&(cs1[i]==cs2[i])){ if(cs1[i]>='A'&&cs1[i]<='G'){ flag=true; weekday=weekdays[cs1[i]-'A']; } } }else{ if(cs1[i]==cs2[i]){ if(Character.isDigit(cs1[i])){ hour=cs1[i]-'0'; break; }else if(cs1[i]>='A'&&cs1[i]<='N'){ hour=cs1[i]-'A'+10; break; } } } } String s3=sc.next(); String s4=sc.next(); int len2=Math.min(s3.length(),s4.length()); char []cs3=s3.toCharArray(); char []cs4=s4.toCharArray(); for(int i=0;i<len2;++i){ if(Character.isLetter(cs3[i])&&Character.isLetter(cs4[i])&&(cs3[i]==cs4[i])){ minute=i; break; } } System.out.printf("%s %02d:%02d",weekday,hour,minute); } }
If you have a better and more convenient way, please comment. I am a rookie and hope to improve.