The Java quiz: Sherlock Holmes's date

Source: Internet
Author: User

Original title address: https://www.nowcoder.com/pat/6/problem/4040

To prevent suspicion of advertising, originally entitled:

Title Description
Sherlock Holmes received a strange note: "Let's date!" 3485djdkxh4hhge 2984AKDFKKKKGGEDSB s&hgsfdk d&hyscvnm ". Big Detective is
Soon to understand, the note on the strange garbled is actually the date of the time "Thursday 14:04", because the first two strings in the 1th pair of the same uppercase English letter (case sensitivity) is
The 4th letter ' D ', representing Thursday; the 2nd pair of the same character is ' E ', that is the 5th letter, representing the first 14 of the day (so that the day's 0 to 23 points from the number 0 to 9,
and capital letters A through n), followed by two strings 1th on the same English letter ' s ' appearing in the 4th position (counting from 0), representing the 4 minute. Now given two pairs of strings,
Please help Holmes decode the time to get the appointment.

Input Description:
The input gives 4 non-empty, space-free, and 60-length strings in 4 rows.


Output Description:
The time to output an appointment in a row, in the form "Day hh:mm", where "days" is a 3-character abbreviation for a week, that is, Mon for Monday, Tue for Tuesday, Wed for Wednesday, Thu for the week

Four, Fri said in Friday, Sat said Saturday, Sun said Sunday. The topic input guarantees that each test has a unique solution.

Input Example:
3485djdkxh4hhge

2984akDfkkkkggEdsb

S&hgsfdk

D&hyscvnm

Output Example:
THU 14:04

It took more than 2 hours to finally debug the code as follows:

Package Ceshi;

import java.util.Arrays;
import java.util.List;
import Java.util.Scanner;
import Java.util.Vector;

/**
* Created by Mrma on 17-4-10.
*/
Public class Main {
Public static void Main (string[] args) {
Scanner sc =New Scanner (System.In );
int i =0;
String yu[] =New string[4];

While (I <4) {
Yu[i] = Sc.nextline ();
i++;
}

char a[][] =new Char[yu.Length] [];

int tongyi[] =New int[3];

For (i =0;i<yu.length;i++) {
A[i] = Yu[i].tochararray ();
}
Int J =0;
For (i =0;i<a[0].length;i++) {

if (a[0] [i] = = a[1] [i]) {
if (a[0] [i] >=&& a[0] [i] <=90) {
Tongyi[j] = a[0] [I]-+1;
if (j = =1)
Tongyi[j] + =9;
j + +;
}
if (tongyi[0]! =0 && a[0] [i] >=' 0 ' && a[0] [I]<=' 9 ') {
tongyi[1] = Integer.valueOf (String.valueOf (a[0] [i]));
j + +;
}

}

if (j = =2)
Break ;
}

For (i =0;i<a[2].length;i++) {
if (a[2] [i] = = a[3] [i] && a[2] [I]>=&& a[2] [I]<=122) {
tongyi[2] = i;
Break ;
}
}


String jg="";
Switch (tongyi[0]) {
Case1:
JG ="MON";
Break ;
Case2:
JG ="TUE";
Break ;
Case3:
JG ="WED";
Break ;
Case4:
JG ="THU";
Break ;
Case5:
JG ="FRI";
Break ;
Case6:
JG ="SAT";
Break ;
Case7:
JG ="SUN";
Break ;
}
System.out.print (JG );
System. out.printf ( "%02d", tongyi[ 1]);
System. out.printf ( 2]);

Sc.close ();
}
}
/span>

1.1 Points have progressed. But found that there are a lot of ready-made classes are useless, in order to be concise code, try to use multiple arrays , also found that the char type is a number, the first to go to the string and then to the number.

If there are better suggestions or ideas, I hope you can put forward, thank you.

The Java quiz: Sherlock Holmes's date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.