zoukankan      html  css  js  c++  java
  • [PAT] 1061 Dating (20 分)Java

    Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04 -- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D, representing the 4th day in a week; the second common character is the 5th capital letter E, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.

    Input Specification:

    Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.

    Output Specification:

    For each test case, print the decoded time in one line, in the format DAY HH:MM, where DAY is a 3-character abbreviation for the days in a week -- that is, MON for Monday, TUE for Tuesday, WED for Wednesday, THU for Thursday, FRI for Friday, SAT for Saturday, and SUN for Sunday. It is guaranteed that the result is unique for each case.

    Sample Input:

    3485djDkxh4hhGE 
    2984akDfkkkkggEdsb 
    s&hgsfdk 
    d&Hyscvnm
    

    Sample Output:

    THU 14:04


     1 package pattest;
     2 
     3 import java.io.BufferedReader;
     4 import java.io.IOException;
     5 import java.io.InputStreamReader;
     6 
     7 /**
     8  * @Auther: Xingzheng Wang
     9  * @Date: 2019/2/24 22:01
    10  * @Description: pattest
    11  * @Version: 1.0
    12  */
    13 public class PAT1061 {
    14 
    15     public static void main(String[] args) throws IOException {
    16         String[] weekday = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    17         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    18         String s1 = reader.readLine();
    19         String s2 = reader.readLine();
    20         char[] c = new char[2];
    21         int i = 0;
    22         int hour = 0;
    23         char[] c1 = s1.toCharArray();
    24         char[] c2 = s2.toCharArray();
    25         for (; i < Math.min(c1.length, c2.length); i++) {
    26             if (c1[i] == c2[i] && c1[i] >= 'A' && c1[i] <= 'G') {
    27                 c[0] = c1[i];
    28                 break;
    29             }
    30         }
    31         i++;
    32         for (; i < Math.min(c1.length, c2.length); i++) {
    33             if (c1[i] == c2[i] && ((c1[i] >= 'A' && c1[i] <= 'N') || (c1[i] >= '0' && c1[i] <= '9'))) {
    34                 c[1] = c1[i];
    35                 break;
    36             }
    37         }
    38         hour = (c[1] >= '0' && c[1] <= '9') ? c[1] - '0' : c[1] - 'A' + 10;
    39         String s3 = reader.readLine();
    40         String s4 = reader.readLine();
    41         char[] c3 = s3.toCharArray();
    42         char[] c4 = s4.toCharArray();
    43         int min = 0;
    44         for (i = 0; i < Math.min(c3.length, c4.length); i++) {
    45             if (c3[i] == c4[i]) {
    46                 if ((c1[i] >= 'a' && c1[i] <= 'z') || (c1[i] >= 'A' && c1[i] <= 'Z')) {
    47                     min = i;
    48                     break;
    49                 }
    50             }
    51         }
    52         System.out.print(weekday[c[0] - 'A'] + " ");
    53         System.out.printf("%02d:%02d", hour, min);
    54     }
    55 }
  • 相关阅读:
    vuecli 脚手架总结
    javascript 如何继承父类
    拖拽面向对象的写法
    获得焦点并且复制文本
    使用vuecli脚手架安装的eslint 容易犯错的地方
    javascript 实现分享功能
    原生javascript 获得css样式有几种方法?
    原生javascript 改写的tab选项卡
    [转载]c# 嵌入资源文件
    [转载]C# log4net应用
  • 原文地址:https://www.cnblogs.com/PureJava/p/10498101.html
Copyright © 2011-2022 走看看