結果
| 問題 | No.652 E869120 and TimeZone | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-01-08 18:11:25 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 1,000 ms | 
| コード長 | 1,941 bytes | 
| コンパイル時間 | 1,156 ms | 
| コンパイル使用メモリ | 131,040 KB | 
| 最終ジャッジ日時 | 2025-01-17 10:55:30 | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 30 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:33: warning: ‘l’ may be used uninitialized [-Wmaybe-uninitialized]
   76 |     string t = s.substr(l, r - l);
      |                                 ^
main.cpp:62:23: note: ‘l’ was declared here
   62 |     int x = 0, y = 0, l, r = n;
      |                       ^
            
            ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    string s;
    cin >> a >> b >> s;
    int n = s.length();
    int x = 0, y = 0, l, r = n;
    for(int i = 0; i < n; ++i){
        if(s[i] == '+' || s[i] == '-'){
            l = i + 1;
        }
        if(s[i] == '.'){
            r = i;
            string t = s.substr(i + 1, n - (i + 1));
            for(auto c : t){
                y *= 10;
                y += c - '0';
            }
        }
    }
    string t = s.substr(l, r - l);
    for(auto c : t){
        x *= 10;
        x += c - '0';
    }
    y *= 6;
    a = (a - 9 + 24) % 24;
    if(s[l - 1] == '+'){
        a += x; b += y;
        a += b / 60;
        a %= 24;
        b %= 60;
    }
    else{
        a -= x; b -= y;
        if(b < 0){
            a -= 1;
            b += 60;
        }
        a = (a + 24) % 24;
    }
    cout << setfill('0') << right << setw(2) << a << ':';
    cout << setfill('0') << right << setw(2) << b << '\n';
    return 0;
}
            
            
            
        