前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【小码匠自习室】ABC258-A 代码写的啰嗦了

【小码匠自习室】ABC258-A 代码写的啰嗦了

作者头像
小码匠
发布2022-08-08 13:21:07
3450
发布2022-08-08 13:21:07
举报
文章被收录于专栏:小码匠和老码农

碎碎念

  • 《论当你在赛后才发现你做的两个判断语句是多么愚蠢这件事》

标签

  • 数学

题目地址

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:

代码语言:javascript
复制
K

Output

Print the time K minutes after 21:00 in the format specified in the Problem Statement.

Sample Input 1

代码语言:javascript
复制
63

Sample Output 1

代码语言:javascript
复制
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

代码语言:javascript
复制
45

Sample Output 2

代码语言:javascript
复制
21:45

Sample Input 3

代码语言:javascript
复制
100

Sample Output 3

代码语言:javascript
复制
22:40

题解

小码匠题解

代码语言:javascript
复制
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;
    }
}

小码匠题解

代码语言:javascript
复制
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)

代码语言:javascript
复制
#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;
}

参考题解

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-07-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小码匠和老码农 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 碎碎念
  • 标签
  • 题目地址
  • 問題描述
    • Constraints
      • Input
        • Output
          • Sample Input 1
            • Sample Output 1
              • Sample Input 2
                • Sample Output 2
                  • Sample Input 3
                    • Sample Output 3
                    • 题解
                      • 小码匠题解
                        • 小码匠题解
                          • 参考题解(tourist)
                            • 参考题解
                            领券
                            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档