Uva 12504-Updating a Dictionary(STL, map)

题目大意见紫书P136- -.

大致思路:这道题其实就是一个暴力,看一个map里面的元素的值再另一个map里面是不是相等就行了,至于题目似乎要求字典序。。废话么map本来就是排好序的所以完全不应在意。只不过我把找‘+’ 和 ‘-'写到一个函数里面来减少代码量,当然这种强行减少代码量会多出许多小trick需要花时间解决。。真正比赛赶时间的时候无脑暴力怎么省时间怎么来就行了。具体细节见代码中的注释(其实也没多少Orz)。

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
#define rep(i,a,b) for (int i=a;i<b;i++)
#define Rep(i,a,b) for (int i=a;i>=b;i--)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 1e5+50 ;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;
int T;char ch[2]={'-','+'};
map<string,string> mp[2];
vector<string> change;
void get(int id) {
    string S;
    getline(cin,S);
    for (int i=0;i<S.length();i++) if (!isalpha(S[i])&&!isdigit(S[i])) S[i] = ' ';
    stringstream ss(S);
    string tmp1,tmp2;
    while (ss >> tmp1 >> tmp2 ) mp[id][tmp1] = tmp2;
}

bool Find(int x) {
    bool flag=0;
    int y=1-x;
    map<string,string>::iterator it=mp[x].begin();
    while (it!=mp[x].end()) {
        string Name=it->first,val=it->second;
        if (mp[y].find(Name)==mp[y].end()) {
            if (!flag) {cout << ch[x] << Name ;flag=1;}
            else cout << ',' << Name ;
        } else if (x==0 && mp[x][Name]!=mp[y][Name]) change.push_back(Name);// Orz  本打算change也直接边找边输出的结果发现顺序不对所以必须存起来
        it++;
    }
    if (flag) cout << '\n' ;
    return flag;
}
int main () {
#ifdef LOCAL
	freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
#endif
    cin >> T ;
    getchar();
    while (T--) {
        mp[0].clear();mp[1].clear();
        change.clear();
        get(0);get(1);
        bool f1=Find(1);bool f2=Find(0);// 这里没记错的话是不能直接用 if (Find(0) || Find(1)) 的,不然的话Find(0)成立后就不会执行Find(1)了
        if (!f2&&!f1&&!change.size()) cout << "No changes\n\n" ;
        else {
            for (int i=0;i<change.size();i++) if (!i) cout << '*' << change[i] ;else cout << ',' << change[i];
            if (change.size()) cout << '\n' ;
            cout << '\n' ;
        }
    }
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值