2020-12-27

嵙嵙 OJ 1937

Problem D: 编写函数:几点几分几秒 (Append Code)
Time Limit: 1 Sec Memory Limit: 2 MB
Submit: 1804 Solved: 1212
[Submit][Status]
Description
一天24小时,每小时60分钟,每分钟60秒。一天共有86400秒。
你的任务是编写一个程序,输入一个在0~86399之间的整数n,输出n对应的时间(从00:00:00到23:59:59)。

     编写两个函数to_time()和put_time()完成程序:
               原型:struct time to_time(int n);
               功能:把参数n换算为用结构体time表示的时间。
               原型:int put_time(struct time t);
               功能:按格式输出t。
     函数的调用格式见“Append Code”。

     “Append Code”中用到如下类型的定义:
               struct time{
                        int hh; // 时
                        int mm; // 分
                        int ss; //秒
               } ;

Input
输入为若干整数n,表示每天的第n秒,0<=n<=86399,至EOF结束。
Output
每行输出一个整数n对应的具体时间,格式为“hh:mm:ss”。时、分、秒各占2位,不足两位要补0,如0点0分0秒为“00:00:00”。
Sample Input
1
2
61
3600
9999
86399
Sample Output
00:00:01
00:00:02
00:01:01
01:00:00
02:46:39
23:59:59
HINT
Append Code
append.c,`

#include<stdio.h>
#include<ctype.h>
#define MAX_STR_LEN 1001
struct time{
                            int hh; // 时
                            int mm; // 分
                            int ss; //秒
                   } ;
struct time to_time(int n)
{
    struct time t;
    t.hh=n/3600;
    t.mm=(n-t.hh*3600)/60;
    t.ss=n-t.hh*3600-t.mm*60;
    return t;
};

int put_time(struct time t)
{
  printf("%02d:%02d:%02d\n",t.hh,t.mm,t.ss);
  return 0;
}


int main()
{
    int n;
    struct time tm;
    while(scanf("%d", &n) != EOF)
    {
        tm = to_time(n);
        put_time(tm);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值