求条
查看原帖
求条
1145420
longyitongxue楼主2025/8/26 17:32
#include<bits/stdc++.h>
using namespace std;
map<string,int> mp1,mp2;
int main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr),cout.tie(nullptr);
    string s;
    while(getline(cin,s)){
        if(s=="------")break;
        int lid=s.find(" ");
        int rid=s.find(" ",lid+1);
        string num1=s.substr(0,lid),num2=s.substr(lid+1,rid-lid-1);
        int n1=stoi(num1),n2=stoi(num2);
        string ren=s.substr(rid+1);
        mp1[ren]+=n2-n1;
    }
    while(getline(cin,s)){
        if(s=="======")break;
        int lid=s.find(" ");
        int rid=s.find(" ",lid+1);
        string num1=s.substr(0,lid),num2=s.substr(lid+1,rid-lid-1);
        int n1=stoi(num1),n2=stoi(num2);
        string ren=s.substr(rid+1);
        mp2[ren]+=n2-n1;
    }
    bool f=1;
    if(mp1.size()<mp2.size()){
        for(auto it:mp2){
            if(mp1.count(it.first)==0){
                f=0;
                cout<<it.first<<" +"<<it.second<<'\n';
                continue;
            }
            if(it.second!=mp1[it.first]){
                f=0;
                cout<<it.first<<' ';
                if(it.second-mp1[it.first]<0)cout<<it.second-mp1[it.first];
                else cout<<'+'<<it.second-mp1[it.first];
                cout<<'\n';
            }
        }
    }else{
        for(auto it:mp1){
            if(mp2.count(it.first)==0){
                f=0;
                cout<<it.first<<" -"<<it.second<<'\n';
                continue;
            }
            if(it.second!=mp2[it.first]){
                f=0;
                cout<<it.first<<' ';
                if(mp2[it.first]-it.second<0)cout<<mp2[it.first]-it.second;
                else cout<<'+'<<mp2[it.first]-it.second;
                cout<<'\n';
            }
        }
    }
    if(f)cout<<"No differences found.";
    return 0;
}
2025/8/26 17:32
加载中...