小乐乐比较懒惰,他现在想睡觉,然后再去学习。他知道现在的时刻,以及自己要睡的时长,想设定一个闹钟叫他起床学习,但是他太笨了,不知道应该把闹钟设定在哪个时刻,请你帮助他。(只考虑时和分,不考虑日期)
小乐乐比较懒惰,他现在想睡觉,然后再去学习。他知道现在的时刻,以及自己要睡的时长,想设定一个闹钟叫他起床学习,但是他太笨了,不知道应该把闹钟设定在哪个时刻,请你帮助他。(只考虑时和分,不考虑日期)
输入现在的时刻以及要睡的时长k(单位:minute),中间用空格分开。
输入格式:hour:minute k(如hour或minute的值为1,输入为1,而不是01)
(0 ≤ hour ≤ 23,0 ≤ minute ≤ 59,1 ≤ k ≤ 109)
对于每组输入,输出闹钟应该设定的时刻,输出格式为标准时刻表示法(即时和分都是由两位表示,位数不够用前导0补齐)。
0:0 100
01:40
1:0 200
04:20
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] toTimeStr = scanner.nextLine().split(":| "); int curHour = Integer.parseInt(toTimeStr[0]); int curMinute = Integer.parseInt(toTimeStr[1]); int toSleepDuration = Integer.parseInt(toTimeStr[2]); curMinute = curMinute + toSleepDuration; curHour = curHour + (curMinute / 60); curMinute = curMinute % 60; curHour = curHour % 24; System.out.println(String.format("%02d",curHour) + ":" + String.format("%02d",curMinute)); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String time = sc.nextLine(); int index1 = time.indexOf(":"); int index2 = time.indexOf(" "); int h = Integer.parseInt(time.substring(0, index1)); int m = Integer.parseInt(time.substring(1 + index1, index2)); int k = Integer.parseInt(time.substring(index2 + 1)); int l = h * 60 + m + k; if (l >= 1440) { l = l % 1440; } int h1 = l / 60; int m1 = l % 60; if (h1 < 10) { System.out.print("0" + h1 + ":"); } else { System.out.print(h1 + ":"); } if (m1 < 10) { System.out.print("0" + m1); } else { System.out.print(m1); } } }
import java.util.Scanner; /** * * @Title 小乐乐定闹钟 * @Description <TODO> * 小乐乐比较懒惰,他现在想睡觉,然后再去学习。 * 他知道现在的时刻,以及自己要睡的时长,想设定一个闹钟叫他起床学习,但是他太笨了, * 不知道应该把闹钟设定在哪个时刻,请你帮助他。(只考虑时和分,不考虑日期) * * 输入描述: * 输入现在的时刻以及要睡的时长k(单位:minute),中间用空格分开。 * * 输入格式:hour:minute k(如hour或minute的值为1,输入为1,而不是01) * * (0 ≤ hour ≤ 23,0 ≤ minute ≤ 59,1 ≤ k ≤ 109) * * 输出描述: * 对于每组输入,输出闹钟应该设定的时刻,输出格式为标准时刻表示法(即时和分都是由两位表示,位数不够用前导0补齐)。 * * @author weijunfu<ijunfu @ qq.com> * @date 2022/03/15 11:41 * @version 1.0.0 * */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] s = in.nextLine().split(" "); String[] times = s[0].split(":"); int hour = Integer.parseInt(times[0]); int minute = Integer.parseInt(times[1]); int minutes = Integer.parseInt(s[1]); minute = minute + minutes; hour += minute/60; minute = minute%60; System.out.printf("%02d:%02d", hour%24, minute); in.close(); } }
注意:一天按24小时计算
//难点:split和模除法进位 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String[] strs = scan.nextLine().split(":| "); int curHour = Integer.parseInt(strs[0]); int curMinute = Integer.parseInt(strs[1]); int minute = Integer.parseInt(strs[2]); curMinute += minute; curHour += (curMinute / 60); curMinute %= 60; curHour %= 24; System.out.printf("%02d:%02d", curHour, curMinute); } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String []clock=sc.nextLine().split("\\:| "); int hour =Integer.parseInt(clock[0]); int minute =Integer.parseInt(clock[1]); int k=Integer.parseInt(clock[2]); while(k>60){ hour++; if(hour>=24){ hour=0; } k-=60; } int l=k+minute; if(l>60){ hour++; l-=60; } System.out.println(String.format("%02d:%02d",hour,l)); } } }
import java.util.*; public class Main{ public static void main(String [] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String str1[] = sc.next().split(":"); int relaxTime = sc.nextInt(); int nowtime[] = new int[10]; int j = 0; for(String i : str1){ nowtime[j++] = Integer.parseInt(i); } int hour = relaxTime/60; int minute = relaxTime%60; nowtime[0] = nowtime[0]+hour; nowtime[1] = nowtime[1]+minute; if(nowtime[1]>=60){ nowtime[0] = nowtime[0]+nowtime[1]/60; nowtime[1] = nowtime[1]%60; } if(nowtime[0]>=24) { nowtime[0] = nowtime[0]%24; } StringBuilder sb = new StringBuilder(); if(nowtime[0]<10){ sb.append("0"+nowtime[0]+":"); } else { sb.append(""+nowtime[0]+":"); } if(nowtime[1]<10){ sb.append("0"+nowtime[1]); } else { sb.append(""+nowtime[1]); } System.out.println(sb); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] str = sc.nextLine().split(" "); int time = Integer.parseInt(str[1]); String[] hourArray = str[0].split(":"); int hour = Integer.parseInt(hourArray[0]); int minute = Integer.parseInt(hourArray[1]); int t = time / 60; int e = time % 60; int newMinute = minute + e; if (newMinute >= 60) { newMinute %= 60; t += 1; } int newHour = hour + t; if (newHour >= 24) { newHour %= 24; } System.out.printf("%02d:%02d\n", newHour, newMinute); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { String[] message = scanner.nextLine().split(" "); String[] hourAndMinute = message[0].split(":"); int hour = Integer.parseInt(hourAndMinute[0]); int minute = Integer.parseInt(hourAndMinute[1]); long clock = Long.parseLong(message[1]); long newMinute = (clock % 60 + minute)%60; long newHour = (clock / 60 + hour + (clock % 60 + minute)/60)%24; System.out.printf("%02d:%02d", newHour, newMinute); } } }//清楚关系式即可
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String[] s = sc.nextLine().split(" "); String[] time = s[0].split(":"); int sleep = Integer.parseInt(s[1]); int hour = sleep/60; int minute = sleep%60; int curH = Integer.parseInt(time[0]); int curM = Integer.parseInt(time[1]); curH = (curH+hour+(minute+curM)/60)%24; curM = (curM+minute)%60; System.out.println(String.format("%02d",curH)+":"+ String.format("%02d",curM)); } } }