习题5-11(uva-12504)

#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>

#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
vector<string> out[3];
map<string, string> ostr;
map<string, string> nstr;

char outFlag[3] = { '+','-','*' };
string key, value;
int cnt = 0;
void Init() {
	for (int i = 0; i < 3; ++i) out[i].clear();
	ostr.clear();
	nstr.clear();
	cnt = 0;
}

void GetMapTree(string &in, map<string, string> &tree) {
	key = value = "";
	int flag = 0;
	for (int i = 0; i < in.size(); ++i) {
		if(in[i] == '{' || in[i] == '}') continue;

		while (in[i] != ':') key += in[i++];i++;

		while (in[i] != ',' && in[i] != '}') value += in[i++];
		tree[key] = value;
		key = value = "";
	}

}
void Print(int index, char ch) {
	vector<string>& a = out[index];
	if (a.empty()) return;
	for (int i = 0; i < a.size(); ++i) {
		if (!i) { cout << ch; }
		else cout << ",";

		cout << a[i];
	}
	cout << endl;
}
int main()
{
	int n;
	cin >> n; cin.ignore();
	string old, ne;
	while (n--) {
		Init();

		getline(cin, old);getline(cin, ne);

		GetMapTree(old, ostr);GetMapTree(ne, nstr);

		for (auto it = nstr.begin();it != nstr.end();++it)
		{
			if (ostr[it->first] == "") { out[0].emplace_back(it->first); cnt++; }
			else if (ostr[it->first] != it->second) { out[2].emplace_back(it->first); cnt++; }
			ostr[it->first] = "";
		}

		for (auto it = ostr.begin(); it != ostr.end(); ++it) {
			if (it->second != "") { out[1].emplace_back(it->first); cnt++; }
		}
		if (cnt == 0) cout << "No changes" << endl;
		else {
			for (int i = 0; i < 3; ++i)Print(i, outFlag[i]);
		}
		cout << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值