結果

問題 No.70 睡眠の重要性!
ユーザー alcheminalchemin
提出日時 2019-09-12 12:11:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,023 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 59,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 14:11:51
合計ジャッジ時間 969 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:13: warning: ‘total’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << total << endl;
             ^~~~~
main.cpp:40:12: warning: ‘nd’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         nd += stoi(tm);
         ~~~^~~~~~~~~~~
main.cpp:28:13: warning: ‘stt’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         stt += stoi(tm);
         ~~~~^~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    int total;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        string start;
        string end;
        
        cin >> start >> std::ws >> end;
        
        string tm;
        int stt;
        for (int j = 0; j < start.length(); j++) {
            if (start[j] == ':') {
                stt = 60 * stoi(tm);
                tm = "";
            } else {
                tm += start[j];
            }
        }
        stt += stoi(tm);
        
        tm = "";
        int nd;
        for (int k = 0; k < end.length(); k++) {
            if (end[k] == ':') {
                nd = 60 * stoi(tm);
                tm = "";
            } else {
                tm += end[k];
            }
        }
        nd += stoi(tm);
        
        if (nd > stt) {
            total += nd - stt;
        } else {
            total += (60 * 24 - stt) + nd;
        }
    }
    
    cout << total << endl;
    
    return 0;
}
0