美文网首页
PAT-B-1014. 福尔摩斯的约会(Java)

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

作者: GeekMonKey | 来源:发表于2016-12-01 21:43 被阅读298次

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

    package com.hym.PAT_B;
    
    import java.util.Scanner;
    
    /**
     * Created by ymhou on 2016/11/22.
     * PAT官网运行超时(100ms运行时间限制),牛客网运行通过
     */
    public class PAT_B_1014 {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            String inputString[] = new String[4];
            for(int i=0; i<4; i++){
                inputString[i] = scanner.next();
            }
    
            int stringSize1,stringSize2;
            if(inputString[0].length() >= inputString[1].length()){
                stringSize1 = inputString[1].length();
            }else {
                stringSize1 = inputString[0].length();
            }
            if(inputString[2].length() >= inputString[3].length()){
                stringSize2 = inputString[3].length();
            }else {
                stringSize2 = inputString[2].length();
            }
    
            int Dayindex=0,Hourindex=0,minuteindex=0,flag=0;
            for(int i=0; i<stringSize1; i++){
                if(inputString[0].charAt(i) == inputString[1].charAt(i)){
                    if(flag==0 && inputString[0].charAt(i)>='A' && inputString[0].charAt(i)<='G'){
                        Dayindex = i;
                        flag++;
                        continue;
                    }
                    if(flag!=0 && ((inputString[0].charAt(i)>='A' && inputString[0].charAt(i)<='N') || (inputString[0].charAt(i)>='0' && inputString[0].charAt(i)<='9'))){
                        Hourindex = i;
                        break;
                    }
    
                }
            }
    
            for(int i=0; i<stringSize2; i++){
                if(inputString[2].charAt(i) == inputString[3].charAt(i) && ((inputString[2].charAt(i)>='A' && inputString[2].charAt(i)<='Z')||(inputString[2].charAt(i)>='a' && inputString[2].charAt(i)<='z'))){
                    minuteindex = i;
                    break;
                }
            }
    
            String dayArray[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
            System.out.print(dayArray[(int)inputString[0].charAt(Dayindex)-65]+" ");
            char hour = inputString[0].charAt(Hourindex);
            if(hour>57){
                System.out.print(String.format("%02d",(int) hour-55));
            }else {
                System.out.print(String.format("%02d",(int) hour-48));
            }
            System.out.print(":"+String.format("%02d",minuteindex));
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:PAT-B-1014. 福尔摩斯的约会(Java)

          本文链接:https://www.haomeiwen.com/subject/cvlfmttx.html