PAT1014题 福尔摩斯的约 JAVA版本

os:看了下别人写的代码太乱 干脆自己写

import java.util.Scanner;

/*
总体思路:
	接收四行参数
	通过index指针遍历字符串
	时间复杂度O(1)
*/
public class Main{
	//打表 为了拿到日期对应的字符串
    static String[] tableDay={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a=sc.nextLine();
        String b=sc.nextLine();
        String c=sc.nextLine();
        String d=sc.nextLine();
        
        int i=0;
        StringBuffer stb=new StringBuffer();//存储拼接字符串
       //时间
        while (i<a.length()&&i<b.length()){
            char temp = a.charAt(i);
            //条件很苛刻 必须在A-G之间
            if (temp>='A'&&temp<='G'&&a.charAt(i)==b.charAt(i)){
                stb.append(tableDay[temp-65]+" ");
                i++;
                break;
                //跳出循环
            }
            i++;
        }
        //小时
        while (i<a.length()&&i<b.length()){
            char temp=a.charAt(i);
            if (temp==b.charAt(i)){
            		//分情况是为了更好拼接字符串
                if (temp>='A'&&temp<='N'){ 
                    stb.append(temp-55+":");
                    break; 
                }
                if (temp<='9'&&temp>='0'){ 
                    stb.append("0"+temp+":");
                    break;  
                }
            }
            i++;
        }
        //分钟
        i=0;
        while (i<c.length()&&i<d.length()){
            char temp=c.charAt(i);
            //注意条件 A-z
            if (temp==d.charAt(i)&&temp>='A'&&temp<='z'){
            //分情况是为了更好拼接字符串
                if (i<=9)  stb.append("0" + i);
                if (i>=10) stb.append(i);
                break;
            }
            i++;
        }
        System.out.print(stb);
        sc.close();
    }
}

任何问题可留言评论区!
2022年11月3日

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值