函数题:地球时间-引用 - C/C++ 指针及引用
(地球时间)以第3章微实践-地球时间的代码为基础,实现下述getTime()函数,将当前小时、分钟和秒数写入参数h、m和s所引用的整数对象。
### 函数接口定义:
c++
void getTime(int& h, int& m, int& s);
### 裁判测试程序样例:
c++
#include <stdio.h>
#include <time.h>
//在此处定义getTime()函数
int main()
{
int h = 0, m = 0, s = 0;
getTime(h,m,s);
printf("%d:%d:%d",h,m,s);
return 0;
}
以下是第3章微实践-地球时间的源代码:
//Project - EarthTime
#include <stdio.h>
#include <time.h>
int main() {
time_t t;
time(&t); //获取当前时间,从1970年1月1日零时起经过的秒数
long long totalSeconds = (long long)t; //总秒数转换为long long类型
long long curSecond = totalSeconds % 60; //当前秒数 = 总秒数对60取余
long long totalMinutes = totalSeconds / 60; //总分钟 = 总秒数除60
long long curMinute = totalMinutes % 60; //当前分钟 = 总分钟对60取余
long long totalHours = totalMinutes / 60; //总小时 = 总分钟除60
long long curHour = totalHours % 24; //当前小时 = 总小时对24取余
printf("格林尼治时间 %lld 时 %lld 分 %lld 秒,1970年1月1日零时到现在经过了 %lld 秒.",
curHour,curMinute,curSecond,totalSeconds);
/* printf的英文版本
printf("%lld:%lld:%lld, %lld seconds after 1970/1/1 00:00::00",
curHour,curMinute,curSecond,totalSeconds);
*/
return 0;
}
### 输入样例:
in
### 输出样例:
out
OK
注意: OJ系统在后台运行正确的函数以及答题者的函数,并比较两者结果的一致性。请读者忽略上述输出样例。
说明:该程序获得的格林威治时间,同北京时间相差8个小时。
请注意:函数题只需要提交相关函数的定义代码,不要提交完整程序。
### 感觉不会? 那试着听听**免费的B站网课**
[简洁的C和C++ - 重庆大学在线课程](https://www.bilibili.com/video/BV1it411d7zx/)
[Python编程基础及应用 - 重庆大学在线课程](https://www.bilibili.com/video/BV1kt411R7uW/)

答案:若无答案欢迎评论
### 函数接口定义:
c++
void getTime(int& h, int& m, int& s);
### 裁判测试程序样例:
c++
#include <stdio.h>
#include <time.h>
//在此处定义getTime()函数
int main()
{
int h = 0, m = 0, s = 0;
getTime(h,m,s);
printf("%d:%d:%d",h,m,s);
return 0;
}
以下是第3章微实践-地球时间的源代码:
//Project - EarthTime
#include <stdio.h>
#include <time.h>
int main() {
time_t t;
time(&t); //获取当前时间,从1970年1月1日零时起经过的秒数
long long totalSeconds = (long long)t; //总秒数转换为long long类型
long long curSecond = totalSeconds % 60; //当前秒数 = 总秒数对60取余
long long totalMinutes = totalSeconds / 60; //总分钟 = 总秒数除60
long long curMinute = totalMinutes % 60; //当前分钟 = 总分钟对60取余
long long totalHours = totalMinutes / 60; //总小时 = 总分钟除60
long long curHour = totalHours % 24; //当前小时 = 总小时对24取余
printf("格林尼治时间 %lld 时 %lld 分 %lld 秒,1970年1月1日零时到现在经过了 %lld 秒.",
curHour,curMinute,curSecond,totalSeconds);
/* printf的英文版本
printf("%lld:%lld:%lld, %lld seconds after 1970/1/1 00:00::00",
curHour,curMinute,curSecond,totalSeconds);
*/
return 0;
}
### 输入样例:
in
### 输出样例:
out
OK
注意: OJ系统在后台运行正确的函数以及答题者的函数,并比较两者结果的一致性。请读者忽略上述输出样例。
说明:该程序获得的格林威治时间,同北京时间相差8个小时。
请注意:函数题只需要提交相关函数的定义代码,不要提交完整程序。
### 感觉不会? 那试着听听**免费的B站网课**
[简洁的C和C++ - 重庆大学在线课程](https://www.bilibili.com/video/BV1it411d7zx/)
[Python编程基础及应用 - 重庆大学在线课程](https://www.bilibili.com/video/BV1kt411R7uW/)

答案:若无答案欢迎评论