习题-ranko的手表(字符串时间问题)

习题-ranko的手表

#include <bits/stdc++.h>
using namespace std;

bool check(int x, string s){
    if(s[0] != '?' && x / 60 / 10 != s[0] - '0') return false;
    if(s[1] != '?' && x / 60 % 10 != s[1] - '0') return false;
    if(s[3] != '?' && x % 60 / 10 != s[3] - '0') return false;
    if(s[4] != '?' && x % 60 % 10 != s[4] - '0') return false;
    return true;
}

signed main(){
    string s1, s2; cin >> s1 >> s2;
    int minv = 24 * 60, maxv = 1;
    for(int i = 0; i < 24 * 60; ++i){
        for(int j = i + 1; j < 24 * 60; ++j){
            if(check(i, s1) && check(j, s2)){
                minv = min(minv, j - i);
                maxv = max(maxv, j - i);
            }
        }
    }
    
    cout << minv << " " << maxv << endl;    
    
    return 0;
}
posted @ 2025-03-27 20:50  awei040519  阅读(8)  评论(0)    收藏  举报