zoukankan      html  css  js  c++  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 表示星期日。题目输入保证每个测试存在唯一解。

    public class Holmes {
    
    
    
            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;
                boolean isMin = 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;
                            }
                        }
                    }
    
                }
                //查找分钟
                for (int i = 0; i < three.length() && i < four.length(); i++) {
                    if(three.charAt(i)  ==  four.charAt(i)) {
                        if( !isMin && (Character.isUpperCase(three.charAt(i)) || Character.isLowerCase(three.charAt(i))) ) {
                              isMin = true;
                              System.out.printf(":%02d", i);
                        }
                    }
                }
    
            }
    
    }
  • 相关阅读:
    #include <boost/shared_array.hpp>
    #include <boost/shared_ptr.hpp>
    #include <boost/scoped_array.hpp>
    df命令
    telnet命令
    sort 命令
    苏宁大数据面试题
    hive严格模式
    k-means伪代码
    vim编辑器
  • 原文地址:https://www.cnblogs.com/moris5013/p/11507637.html
Copyright © 2011-2022 走看看