题解分享
题解分享简介
时间显示(编程题) - 题解
我三年级,我写完啦
```
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
using namespace std;
int h,m,s;
int main()
{
//46800
long long n;
cin>>n;
n /= 1000;
h = n / 60 / 60 % 24;
m = n / 60 % 60;
s = n % 60 % 60;
if(h == 0)
{
cout<<"00:";
}
else if(h > 0 && h < 10)
{
cout<<"0"<<h<<":";
}
else
{
cout<<h<<":";
}
if(m == 0)
{
cout<<"00:";
}
else if(m > 0 && m < 10)
{
cout<<"0"<<m<<":";
}
else
{
cout<<m<<":";
}
if(s == 0)
{
cout<<"00";
}
else if(s > 0 && s < 10)
{
cout<<"0"<<s;
}
else
{
cout<<s;
}
return 0;
}
```
查看全文
0
0
1
11
时间显示(编程题) - 题解
简单题不多说了
```
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;cin >> n;//输入数据
n = n / 1000;//将毫秒转换成秒
int s = n % 60;//获取剩余的秒
n /= 60;//将秒转换成分钟
int m = n % 60;//获取剩余的分钟
n /= 60;//将分钟转化成小时
int h = n % 24;//获取剩余的小时
printf("%02d:%02d:%02d", h, m, s);//按照题目格式输出
return 0;
}
```
查看全文
0
0
2
14
时间显示(编程题) - 题解
```
#include<cstdio>
using namespace std;
typedef long long ll;
int main(){
ll h;
scanf("%lld",&h);
int hh,mm,ss;
h = h % (24*60*60*1000);//得到一天之内的毫秒数
hh = h/(60*60*1000)%24;//计算小时数
mm = h/(60*1000)%60;//计算分钟数
ss = h/(1000)%60;//计算秒数
printf("%02d:%02d:%02d\n",hh,mm,ss);
return 0;
}
```
查看全文
0
0
1
14
时间显示(编程题) - 题解
极简代码
```cpp
#include <iostream>
using namespace std;
int main()
{
long long n;
cin >> n;
n /= 1000LL;
n %= 24LL * 60 * 60;
printf("%02lld:%02lld:%02lld\n",
n / 3600LL, (n % 3600LL) / 60, n % 60);
return 0;
}
```
查看全文
0
0
1
8
时间显示(编程题) - 题解
```import
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner inputScanner = new Scanner(System.in);
String s = inputScanner.next();
// 将输入的字符串转换为 BigInteger
BigInteger bigInteger = new BigInteger(s);
// 每小时、每分钟、每秒的毫秒数
BigInteger shi = new BigInteger("3600000"); // 1小时 = 3600000毫秒
BigInteger fen = new BigInteger("60000"); // 1分钟 = 60000毫秒
BigInteger miao = new BigInteger("1000"); // 1秒 = 1000毫秒
// 计算小时数
BigInteger hours = bigInteger.divide(shi);
BigInteger hourss = hours.remainder(new BigInteger("24"));
// 计算剩余的毫秒数
BigInteger remainingMillisAfterHours = bigInteger.remainder(shi);
// 计算分钟数
BigInteger minutes = remainingMillisAfterHours.divide(fen);
// 计算剩余的毫秒数
BigInteger remainingMillisAfterMinutes = remainingMillisAfterHours.remainder(fen);
// 计算秒数
BigInteger seconds = remainingMillisAfterMinutes.divide(miao);
// 输出结果
System.out.printf("%02d", hourss); // 打印小时,格式化为两位数
System.out.print(":");
System.out.printf("%02d", minutes); // 打印分钟,格式化为两位数
System.out.print(":");
System.out.printf("%02d", seconds); // 打印秒,格式化为两位数
}
}
```
查看全文
0
0
0
6
时间显示(编程题) - 题解
```
import java.util.*;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long timestamp = sc.nextLong();
// 调用convertTimestampToString方法,将时间戳转换为HH:MM:SS格式的字符
String timeString = convertTimestampToString(timestamp);
System.out.println(timeString);
}
public static String convertTimestampToString(long timestamp) {
// 创建Date对象
Date date = new Date(timestamp);
// 创建一个SimpleDateFormat对象,用于格式化日期
// "HH:mm:ss"是日期格式字符串,表示24小时制的小时(HH)、分钟(mm)和秒(ss)
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
// 将Date对象格式化为字符串
return sdf.format(date);
}
}
`
```
`
查看全文
0
0
0
18
时间显示(编程题) - 题解
```cpp
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define LL long long
#define endl '\n'
void solve()
{
LL n;
cin >> n;
n %= 24 * 60 * 60 * 1000; // 处理时间超过一天的情况,即去除年月日部分,提取时间
n /= 1000; // 将毫秒数转换为秒数,即去除毫秒部分
int sec = n % 60; // 计算秒数,取秒数部分
n /= 60; // 将秒数转换为分钟,即去除秒数部分
int minu = n % 60; // 计算分钟,取分钟部分
n /= 60; // 将分钟转换为小时,即去除分钟部分
int hour = n; // 计算分钟,取小时部分
printf("%02d:%02d:%02d", hour, minu, sec);
}
signed main()
{
// ios::sync_with_stdio(0);
// cin.tie(0), cout.tie(0);
solve();
return 0;
}
```
查看全文
0
0
0
17
时间显示(编程题) - 题解
```
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long nt, time, second, hour;
cin >> nt;
time = (nt / 1000) % 60;
second = ((nt / 1000) / 60) % 60;
hour = (((nt / 1000) / 60) / 60) % 24;
printf("%02d:%02d:%02d", hour, second, time);
return 0;
}
```
查看全文
0
0
0
15
时间显示(编程题) - 题解
```
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
ll a;
ll s,m,h;
a=n/1000;
s=a%60%60;
m=a/60%60;
h=a/60/60;
while(h>=24) h=h%24;
printf("%02lld:%02lld:%02lld",h,m,s);
return 0;
}
```
查看全文
0
0
0
12
时间显示(编程题) - 题解
```
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int a,b,c;
long long n;
cin>>n;
n=n/1000%(3600*24);
//毫秒换成秒,%一天的秒数,使n数量小于一天
a=n/3600; //多少小时
n%=3600; //分钟加上秒的总时间
b=n/60; //分钟
c=n%60; //秒
printf("%02d:%02d:%02d",a,b,c); //02是为了始终有两位数字
return 0;
}
```
查看全文
0
0
0
9



