挚爱 题解分享 · 2025/3/20
时间显示(编程题) - 题解
我三年级,我写完啦 ``` #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 2
desert 题解分享 · 2024/4/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 1 3
Dome 题解分享 · 2024/4/4
时间显示(编程题) - 题解
``` #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 3
chushiyue 题解分享 · 2024/4/4
时间显示(编程题) - 题解
极简代码 ```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 2
acloser 题解分享 · 2025/3/12
时间显示(编程题) - 题解
```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 2
didhv 题解分享 · 2024/4/4
时间显示(编程题) - 题解
``` 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 7
yuri01 题解分享 · 2024/12/18
时间显示(编程题) - 题解
```cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, h, m, s; int main() { scanf("%lld", &n); n %= 1000 * 60 * 60 * 24; h = n / (1000 * 60 * 60); n %= (1000 * 60 * 60); m = n / (1000 * 60); n %= (1000 * 60); s = n / 1000; printf("%02ld:%02ld:%02ld", h, m, s); } ```
查看全文
0 0 0 2
kaisyuantseng 题解分享 · 2024/4/11
时间显示(编程题) - 题解
```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 2
bkbqwq 题解分享 · 2024/4/10
时间显示(编程题) - 题解
``` #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 2
Liopen 题解分享 · 2024/4/10
时间显示(编程题) - 题解
``` #include<cstdio> #include<iostream> using namespace std; int main(){ long long time=0; cin>>time; time=(time/1000)%(24*60*60); int h=time/(60*60); int m=(time-60*60*h)/60; int s=time-60*60*h-60*m; printf("%02d:%02d:%02d",h,m,s); return 0; } ```
查看全文
0 0 0 2