{ "question_id": 1058389, "question_title": "秒数转换", "question_content": "输入一个秒数,转换成HH:MM:SS的格式输出。\n输入样例 \n365\n输出样例 \n00:06:05", "difficulty": "简单", "answer_id": 1255698, "answer_content": "\n```\n#include<cstdio>\nint n;\nvoid print(int x){\n\tif(x==0)printf(\"00\");\n\telse if(x<10)printf(\"0%d\",x);\n\telse printf(\"%d\",x);\n\treturn;\n}\nint main(){\n\tscanf(\"%d\",&n);\n\tint s,f,m;\n\ts=n/3600;\n\tf=n/60%60;\n\tm=n%60;\n\tprint(s);\n\tprintf(\":\");\n\tprint(f);\n\tprintf(\":\");\n\tprint(m);\n\treturn 0;\n}\n```\n如果还没有学过函数的话,可以这么做\n\n```\n#include<cstdio>\nint n;\nint main(){\n\tscanf(\"%d\",&n);\n\tprintf(\"%d%d:%d%d:%d%d\",n/3600/10,n/3600%10,n/60%60/10,n/60%10,n%60/10,n%10);\n\treturn 0;\n}\n```", "tag_name": "c++", "cpp": "#include<cstdio>\nint n;\nvoid print(int x){\n\tif(x==0)printf(\"00\");\n\telse if(x<10)printf(\"0%d\",x);\n\telse printf(\"%d\",x);\n\treturn;\n}\nint main(){\n\tscanf(\"%d\",&n);\n\tint s,f,m;\n\ts=n/3600;\n\tf=n/60%60;\n\tm=n%60;\n\tprint(s);\n\tprintf(\":\");\n\tprint(f);\n\tprintf(\":\");\n\tprint(m);\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600470176", "status": 1, "keywords": "时间转换", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/105.ipynb?type=file" }, "notebook_enable": 1 }