50分求助qwq

P5707 【深基2.例12】上学迟到

the_nth_peoplo @ 2024-09-22 00:19:27

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int main() {

    int a, b,c;
    cin >> a >> b ;
    if (a % b != 0) { c = (a - a % b) / b + 1; }
    else{ c = (a - a % b) / b ; }
    if (8 - (c - c % 60) / 60 - 1 >= 0) {
        if (c % 60 != 0) {
            if (60 - ((c + 10) % 60) >= 10) {
                if ((c + 10) % 60 == 0) {
                    printf("0%d:00", 8 - (c - c % 60) / 60 - 1);
                }
                else {
                    printf("0%d:%d", 8 - (c - c % 60) / 60 - 1, 60 - ((c + 10) % 60));
                }
            }
            else {
                printf("0%d:0%d", 8 - (c - c % 60) / 60 - 1, 60 - ((c + 10) % 60));
            }
        }
        else {
            if (60 - ((c + 10) % 60) >= 10) {
                if ((c + 10) % 60 == 0) {
                    printf("0%d:00", 8 - (c - c % 60) / 60 - 1);
                }
                else {
                    printf("0%d:%d", 8 - (c - c % 60) / 60 - 1, 60 - ((c + 10) % 60));
                }
            }
            else {
                printf("0%d:0%d", 8 - (c - c % 60) / 60, 60 - ((c + 10) % 60));
            }
        }
    }
    else{
        if (c % 60 != 0) {
            if (60 - ((c + 10) % 60) >= 10) {
                if ((c + 10) % 60 == 0) {
                    printf("0%d:00", 8 - (c - c % 60) / 60 +23);
                }
                else {
                    printf("0%d:%d", 8 - (c - c % 60) / 60 +23, 60 - ((c + 10) % 60));
                }
            }
            else {
                printf("0%d:0%d", 8 - (c - c % 60) / 60 +23, 60 - ((c + 10) % 60));
            }
        }
        else {
            if (60 - ((c + 10) % 60) >= 10) {
                if ((c + 10) % 60 == 0) {
                    printf("0%d:00", 8 - (c - c % 60) / 60 +23);
                }
                else {
                    printf("0%d:%d", 8 - (c - c % 60) / 60 +23, 60 - ((c + 10) % 60));
                }
            }
            else {
                printf("0%d:0%d", 8 - (c - c % 60) / 60+24, 60 - ((c + 10) % 60));
            }
        }
    }
    return 0;
}

by the_nth_peoplo @ 2024-09-22 00:30:19

修复了前面一天h多一个0的bug,现在80分了qwq


by the_nth_peoplo @ 2024-09-22 00:30:53

@the_nth_peoplo 就是4和7不行


by st2010 @ 2024-09-22 01:23:06

@the_nth_peoplo 感觉你的代码很乱,而且这道题不用打这么多代码


by st2010 @ 2024-09-22 01:27:04

@the_nth_peoplo 你的我改不了,但给你看看这个

#include <iostream>
using namespace std;

int main()
{
    int s, v;
    int t;
    int h, m;
    int hh, mm;
    cin >> s >> v;
    t = s / v;
    if (s % v)
    {
        t++;
    }
    t += 10;
    h = t / 60;
    m = t % 60;
    hh = 7 - h;
    mm = 60 - m;
    while (hh < 0)
    {
        hh += 24;
    }
    printf("%02d:%02d", hh, mm);
    return 0;
}

by st2010 @ 2024-09-22 01:30:43

@the_nth_peoplo 去学一下循环吧


by the_nth_peoplo @ 2024-09-25 15:55:38

@st2010 有道理


|