题解 | #ranko的手表#

ranko的手表

https://www.nowcoder.com/practice/37275e85ae7c4453920eae6b9f7f45fc

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String t1 = sc.nextLine();
        String t2 = sc.nextLine();
        //用于存储符合规则的字符串
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        //24小时存储符合规则的时间
        for (int i = 0; i < 60 * 24; i++) {
            int hour = i / 60;
            int minu = i % 60;
            if ((t1.charAt(0) == '?' || t1.charAt(0) - '0' == hour / 10) &&
                    (t1.charAt(1) == '?' || t1.charAt(1) - '0' == hour % 10)
                    && (t1.charAt(3) == '?' || t1.charAt(3) - '0' == minu / 10) &&
                    (t1.charAt(4) == '?' || t1.charAt(4) - '0' == minu % 10))
                list1.add(i);
            if ((t2.charAt(0) == '?' || t2.charAt(0) - '0' == hour / 10) &&
                    (t2.charAt(1) == '?' || t2.charAt(1) - '0' == hour % 10)
                    && (t2.charAt(3) == '?' || t2.charAt(3) - '0' == minu / 10) &&
                    (t2.charAt(4) == '?' || t2.charAt(4) - '0' == minu % 10))
                list2.add(i);
        }
        int max = 0;
        int min = 60 * 24;
        for(int i = 0;i<list1.size();i++)
            for(int j = 0;j<list2.size();j++){
                if(list1.get(i) < list2.get(j)){
                    max = Math.max(list2.get(j)-list1.get(i),max);
                    min = Math.min(list2.get(j)-list1.get(i),min);
                }
            }
        System.out.println(min+" "+max);
    }   
}

全部评论

相关推荐

09-22 11:42
门头沟学院 Java
现在还很懵,不是什么很好的工资,但是很怕拒绝了秋招就没有offer了试用期3个月&nbsp;无责底薪7k➕绩效&nbsp;转正8k&nbsp;base南昌&nbsp;没有住房补贴&nbsp;餐补&nbsp;不知道作为一个应届生这个待遇怎么样?
白火同学:南昌能给到8k,还有绩效其实不错了。因为南昌房租不高,我22年在谢家村那边市中心租房只要1k就能租到还不错的房子,其他消费也是正常省会水平,所以南昌8k ≈ 一线10k上下吧。双非应届校招能拿这个薪资水平确实可以了,唯一不足的就是南昌IT行业整体不太行,以后跳槽多少有点不方便。
我的秋招日记
点赞 评论 收藏
分享
驼瑞驰_招募评论官版...:一共经历几次握手?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务