有谁帮我看一下吗,错了一个点
查看原帖
有谁帮我看一下吗,错了一个点
993368
JshGLJ楼主2023/9/26 21:16
#include <iostream>
#include <string>

// 将时间转换为秒数
int timeToSeconds(const std::string& timeStr) {
    int hours, minutes, seconds;
    sscanf(timeStr.c_str(), "%d:%d:%d", &hours, &minutes, &seconds);
    return hours * 3600 + minutes * 60 + seconds;
}

int main() {
    // 输入
    std::string start_time, end_time;
    int n;
    std::cin >> start_time >> end_time >> n;

    // 时间转换为秒数
    int start_seconds = timeToSeconds(start_time);
    int end_seconds = timeToSeconds(end_time);

    // 计算时间差
    int time_diff = end_seconds - start_seconds;

    // 计算猪八戒能偷到的笔记本数量
    int notebooks = n * time_diff;

    // 输出结果
    std::cout << notebooks << std::endl;

    return 0;
}
2023/9/26 21:16
加载中...