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

vector<int> v1,v2;

int cal(string str){
    int res = ((str[0]-'0') * 10 + (str[1]-'0')) * 60+ 
    (str[2]-'0') * 10 + (str[3]-'0');
    return res%1440;
}

void dfs(string str,int u,int op){

    if(u==int(str.size())){
        if(stoi(str.substr(0,2))>23) return;
        if(stoi(str.substr(2))>59) return;

        if(op==1) v1.emplace_back(cal(str));
        else v2.emplace_back(cal(str));
        return;
    }

    if(str[u]=='?'){
        for(char i = '0';i<='9';i++){
            string t = str;
            t[u] = i;
            dfs(t,u+1,op);
        }
    }
    else{
        dfs(str,u+1,op);
    }

}

int main(){
    string str1,str2;
    cin>>str1>>str2;
    
    str1 = str1.substr(0,2) + str1.substr(3);
    str2 = str2.substr(0,2) + str2.substr(3);

    dfs(str1,0,1);
    dfs(str2,0,2);

    int ma = -1e9,mi = 1e9;
    for(auto a : v1){
        for(auto b : v2){
            if(a>=b) continue;
            ma = max(ma,b-a);
            mi = min(mi,b-a);
        }
    }

    cout<<mi<<" "<<ma;

    return 0;
}

暴力算出各种结果,然后for循环计算最大,最小值

#牛客春招刷题训练营#https://www.nowcoder.com/discuss/727521113110073344