PAT 1014 福尔摩斯的约会 (20 分) Java实现

https://github.com/salmon1802/PAT_B

在我挣扎了一个小时后我看了下别人写的代码,我发现我自己是个傻逼,原来困阻我的不是我的代码编写能力而是我的语文阅读能力,这一题其实是出奇的简单,因为它的字符串是同步扫描的,而不是我想的异步扫描。

在这里附上异步扫描的代码,我是傻逼

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @date 2021-8-8 - 21:55
 * Created by Salmon
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String[] string1 = bufferedReader.readLine().split("");
        String[] string2 = bufferedReader.readLine().split("");
        String[] string3 = bufferedReader.readLine().split("");
        String[] string4 = bufferedReader.readLine().split("");
        int flag = 0;
        int flag1 = 0;
        for(int i = 0; i < string1.length && flag != 2; i++){
                for (int j = 0; j < string2.length; j++){
                    if(string1[i].charAt(0) >= 'A' && string1[i].charAt(0) <= 'Z') {
                        if(string1[i].equals(string2[j]) && flag == 0){
                            print1(string1[i]);
                            flag++;
                            break;
                        }
                    }

                    if((string1[i].charAt(0) >= 'A' && string1[i].charAt(0) <= 'Z') || string1[i].charAt(0) >= '0' && string1[i].charAt(0) <= '9'){
                        if(string1[i].equals(string2[j]) && flag == 1){
                            if(string1[i].charAt(0) >= 'A' && string1[i].charAt(0) <= 'Z'){
                                System.out.print(string1[i].charAt(0) - 'A' + 10 + ":");
                            }else if(string1[i].charAt(0) >= '0' && string1[i].charAt(0) <= '9'){
                                System.out.printf("%02d:",string1[i].charAt(0) - '0');
                            }
                            flag++;
                            break;
                        }
                    }
                }
            }

        for(int i = 0; i < string3.length && flag1 != 1; i++) {
            if(string3[i].charAt(0) >= 'a' && string3[i].charAt(0) <= 'z'){
                for (int j = 0; j < string4.length; j++){
                    if(string3[i].equals(string4[j])){
                        System.out.printf("%02d",j);
                        flag1++;
                        break;
                    }
                }
            }else{
                continue;
            }
        }

    }

    public static void print1(String s){
        switch (s.charAt(0)){
            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;
            case 'F' :
                System.out.print("SAT ");break;
            case 'G' :
                System.out.print("SUN ");break;
        }

    }

}

在这里插入图片描述

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @date 2021-8-8 - 21:55
 * Created by Salmon
 */
public class Main1014 {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String[] string1 = bufferedReader.readLine().split("");
        String[] string2 = bufferedReader.readLine().split("");
        String[] string3 = bufferedReader.readLine().split("");
        String[] string4 = bufferedReader.readLine().split("");
        int flag = 0;
        int flag1 = 0;
        for(int i = 0; i < string1.length && flag != 2; i++) {
            if (string1[i].charAt(0) >= 'A' && string1[i].charAt(0) <= 'Z') {
                if (string1[i].equals(string2[i]) && flag == 0 && (string1[i].charAt(0) >= 'A' && string1[i].charAt(0) <= 'G')) {
                    print1(string1[i]);
                    flag++;
                    continue;
                } else if (string1[i].equals(string2[i]) && flag == 1 && (string1[i].charAt(0) >= 'A' && string1[i].charAt(0) <= 'N')) {
                    System.out.print(string1[i].charAt(0) - 'A' + 10 + ":");
                    flag++;
                    continue;
                }
            }else if (string1[i].charAt(0) >= '0' && string1[i].charAt(0) <= '9' && flag == 1) {
                if(string1[i].equals(string2[i])){
                    System.out.printf("%02d:", string1[i].charAt(0) - '0');
                    flag++;
                }
            }

        }





        for(int i = 0; i < string3.length && flag1 != 1; i++) {
                    if(string3[i].equals(string4[i]) &&
                            (
                                    (string3[i].charAt(0) >= 'A' && string3[i].charAt(0) <= 'Z') ||
                                    (string3[i].charAt(0) >= 'a' && string3[i].charAt(0) <= 'z')
                            )
                    ){
                        System.out.printf("%02d",i);
                        flag1++;
                        break;
                    }
                }

    }




    public static void print1(String s){
        switch (s.charAt(0)){
            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;
            case 'F' :
                System.out.print("SAT ");break;
            case 'G' :
                System.out.print("SUN ");break;
        }

    }

}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值