字节跳动2020届秋招 Java 笔试题
笔试可以在本地IDE写,然后复制上去
第一题 ,问最晚什么时候起床
N:闹钟数 <= 100
HI 小时 Mi 分钟 0 - 24
X 去教室走几分钟 0 - 60
A 上课时间
输入案例:
3 定三个闹钟
5 0 闹钟1
6 0 闹钟2
7 0 闹钟3
59 去教室走几分钟
6 59 几点上课
输出:
6 0
我代码过了 80%,比较菜!!
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
int lasttime = 0;
//记录闹钟,时间最长的在最外面
Stack<Integer> lasttimes = new Stack<Integer>();
for (int i = 0; i < n; i++) {
String[] str = sc.nextLine().split(" ");
//这里将时间统一为分钟
lasttime+=60*Integer.parseInt(str[0]);
lasttime+=Integer.parseInt(str[1]);
lasttimes.push(lasttime);
lasttime=0;
}
//获取去学校时长
lasttime = sc.nextInt();
sc.nextLine();
//获取上课时间
String[] str = sc.nextLine(