其他分享
首页 > 其他分享> > 蓝桥杯真题 时间显示

蓝桥杯真题 时间显示

作者:互联网

问题描述

 

思路

这个题很简单……水个数量

忽略毫秒,直接把最后三位截掉

忽略年月日,对一天的秒数取余(24*3600=86400)

那么怎么取余呢:java直接超大数暴力求解

最后分别求出小时数、分数,剩下的就是秒数

代码

 1 package demo;
 2 
 3 import java.math.BigInteger;
 4 import java.util.Scanner;
 5 
 6 public class Main {
 7     public static void main(String args[]) {
 8         // 24*3600=86400
 9         Scanner in = new Scanner(System.in);
10         String s = in.next();
11         s = s.substring(0, s.length() - 3); // 舍去毫秒
12 //        System.out.println(s);
13         String m = "86400";
14         BigInteger sec = new BigInteger(s);
15         BigInteger mod = new BigInteger(m);
16         sec = sec.mod(mod);
17         BigInteger hour = sec.divide(new BigInteger("3600"));
18         sec = sec.subtract(hour.multiply(new BigInteger("3600")));
19         BigInteger minu = sec.divide(new BigInteger("60"));
20         sec = sec.subtract(minu.multiply(new BigInteger("60")));
21         String h = hour.toString();
22         if (h.length() == 1)
23             h = "0" + h;
24         String mi = minu.toString();
25         if (mi.length() == 1)
26             mi = "0" + mi;
27         String se = sec.toString();
28         if (se.length() == 1)
29             se = "0" + se;
30         System.out.println(h + ":" + mi + ":" + se);
31     }
32 }

 

标签:显示,String,真题,mi,BigInteger,蓝桥,sec,new,se
来源: https://www.cnblogs.com/JaineCC/p/16104602.html