当前位置:网站首页>【小码匠自习室】ABC258-A 代码写的啰嗦了
【小码匠自习室】ABC258-A 代码写的啰嗦了
2022-08-08 13:52:00 【小码匠】
碎碎念
- 《论当你在赛后才发现你做的两个判断语句是多么愚蠢这件事》
标签
- 数学
题目地址
A - When?
- https://atcoder.jp/contests/abc258/tasks/abc258_a
問題描述
AtCoder Beginner Contest usually starts at 21:00 JST and lasts for 100 minutes.
You are given an integer K between 00 and 100100 (inclusive). Print the time K minutes after 21:00 in the HH:MM
format, where HH
denotes the hour on the 24-hour clock and MM
denotes the minute. If the hour or the minute has just one digit, append a 0 to the beginning to represent it as a 2-digit integer.
Constraints
- K is an integer between 0 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the time K minutes after 21:00 in the format specified in the Problem Statement.
Sample Input 1
63
Sample Output 1
22:03
6363 minutes after 21:00, it will be 22:03, so 22:03
should be printed.
The following outputs would be judged incorrect:
10:03
22:3
Sample Input 2
45
Sample Output 2
21:45
Sample Input 3
100
Sample Output 3
22:40
题解
小码匠题解
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int k;
cin >> k;
int h = k / 60;
if (21 + h >= 24) {
if ((21 + h) % 24 < 10) {
cout << 0 << (21 + h) % 24;
} else {
cout << (21 + h) % 24;
}
} else {
cout << 21 + h;
}
cout << ':';
if (k % 60 < 10) {
cout << 0 << k % 60;
} else {
cout << k % 60;
}
}
小码匠题解
void best_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int k;
cin >> k;
int h = k / 60;
cout << 21 + h << ':';
if (k % 60 < 10) {
cout << 0 << k % 60;
} else {
cout << k % 60;
}
}
参考题解(tourist)
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int k;
cin >> k;
int h = 21 + k / 60;
int m = k % 60;
cout << h << ":" << m / 10 << m % 10 << '\n';
return 0;
}
参考题解
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int X;
cin >> X;
int H = X < 60 ? 21 : 22;
int M = X % 60;
printf("%d:%02d", H, M);
return 0;
}
边栏推荐
猜你喜欢
HackTheBox | Previse
【Redis】位图以及位图的使用场景(统计在线人数和用户在线状态)
机器学习+深度学习笔记(持续更新~)
Pretraining Weekly Issue 56: Long Text Understanding, Instant Question Answering, Mask Self-Supervision
Code Casual Recording Notes_Dynamic Programming_322 Change Exchange
Qt操作Sqlite类封装,及命令行导入csv文件到Sqlite数据库
一桩事先张扬的网红书店倒闭案
[Redis] Redis installation and use of client redis-cli (batch operation)
MySQl表的增删查改(CRUD)
[C language] In-depth analysis of data storage in memory
随机推荐
基于FPGA的FIR滤波器的实现(1)—采用fir1函数设计
[Redis] Redis installation and use of client redis-cli (batch operation)
bzoj 3624 [Apio2008]免费道路
Verilog语法基础HDL Bits训练 09
Flink1.15源码阅读——StreamGraph流图
R语言ggpubr包的ggsummarystats函数可视化分面箱图(通过ggfunc参数和facet.by参数设置)、添加描述性统计结果表格、palette参数配置不同水平可视化图像和统计值的颜色
今日睡眠质量记录83分
深入浅出对话系统——任务型对话系统技术框架
Full of dry goods, Yu Jingxin class of the Institute of Information Technology, Chinese Academy of Sciences will help you get academic research and thesis writing skills
SAP数据迁移需要多久?
Knowledge points and written test questions related to shift operations, bit operations, and logical operations
[界面开发]DevExpress WinForms流程图控件——XtraDiagrams组件入门指南
Qt操作Sqlite类封装,及命令行导入csv文件到Sqlite数据库
年初离职,学习半年源码,终于拿到了蚂蚁Offer,分享面试过程
PC端实用软件推荐
【第2天】SQL快速入门-条件查询(SQL 小虚竹)
【os.path】的相关用法(持更)
《预训练周刊》第56期:长文本理解、即时问答、掩码自监督
腾讯,投了个 “离诺贝尔奖最近的华人”
教学习编程,第一步解决自信问题,培养自己的专注力