結果

問題 No.70 睡眠の重要性!
コンテスト
ユーザー alchemin
提出日時 2019-09-12 12:11:56
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,023 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 643 ms
コンパイル使用メモリ 74,940 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-24 01:07:35
合計ジャッジ時間 922 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:45:19: warning: 'total' may be used uninitialized [-Wmaybe-uninitialized]
   45 |             total += (60 * 24 - stt) + nd;
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:8:9: note: 'total' was declared here
    8 |     int total;
      |         ^~~~~
main.cpp:28:13: warning: 'stt' may be used uninitialized [-Wmaybe-uninitialized]
   28 |         stt += stoi(tm);
      |         ~~~~^~~~~~~~~~~
main.cpp:19:13: note: 'stt' was declared here
   19 |         int stt;
      |             ^~~
main.cpp:40:12: warning: 'nd' may be used uninitialized [-Wmaybe-uninitialized]
   40 |         nd += stoi(tm);
      |         ~~~^~~~~~~~~~~
main.cpp:31:13: note: 'nd' was declared here
   31 |         int nd;
      |             ^~

ソースコード

diff #
raw source code

#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