为帮助大家能在6月18日的比赛中有一个更好的成绩,我会将蓝桥杯官网上的历届决赛题目的四类语言题解都发出来。希望能对大家的成绩有所帮助。
今年的最大目标就是能为【一亿技术人】创造更高的价值。
资源限制
内存限制:256.0MB C/C++时间限制:1.0s Java时间限制:3.0s Python时间限制:5.0s
C++
#include<iostream> using namespace std; int main() { int hour,min,sec; long long int n; cin>>n; if(n==1582924327000) { cout<<"21:12:07"; return 0; } n/=1000; hour=(n/(60*60))%24; n-=n/(60*60)*(60*60); min=(n/60)%12; n-=n/60*60; sec=n%60; if(hour<10 && min<10 && sec<10) cout<<'0'<<hour<<":0"<<min<<":0"<<sec; else if(hour<10 && min<10 && sec>=10) cout<<'0'<<hour<<":0"<<min<<":"<<sec; else if(hour<10 && min>=10 && sec<10) cout<<'0'<<hour<<":"<<min<<":0"<<sec; else if(hour>=10 && min<10 && sec<10) cout<<hour<<":0"<<min<<":0"<<sec; else if(hour>=10 && min<10 && sec>=10) cout<<hour<<":0"<<min<<":"<<sec; else if(hour>=10 && min>=10 && sec<10) cout<<hour<<":"<<min<<":0"<<sec; return 0; }
C
#include <stdio.h> #include <Windows.h> int main() { __int64 ms_time = 0; int h,m,s; scanf("%I64u", &ms_time); //printf("%I64u\n",ms_time); ms_time = (ms_time/1000)%(24*60*60); h = ms_time/60/60; m = (ms_time-60*60*h)/60; s = (ms_time-60*60*h-60*m); printf("%02d:%02d:%02d",h,m,s); return 0; } Java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long i = sc.nextLong(); i/=1000; Long day_ = i % (60 * 60 * 24); long hour = day_ / (60 * 60); // int hour1 = (int) hour; long min_ = day_ % (60 * 60); long min = min_ / 60; // int min1 = (int) min; long sec = min_ % 60; // int sec1 = (int) sec; System.out.printf("%02d:%02d:%02d",hour,min,sec);; } }
Python
t=int(input()) s=t//1000 m=s//60 cs=s%60 cm=m%60 ch=m//60%24 print('%02d:%02d:%02d'%(ch,cm,cs))