关注
#include <bits/stdc++.h>
using namespace std;
struct word {
string str;
int cnt;
word(string _s,int _c):str(_s),cnt(_c){}
};
void splitString(const string& s, vector<word>& v, const string& c)
{
string::size_type pos1, pos2, pos;
pos2 = s.find(c);
pos1 = 0;
string tmp;
while (string::npos != pos2) {
//v.push_back(s.substr(pos1, pos2 - pos1));
tmp = s.substr(pos1, pos2 - pos1);
pos = tmp.find(':');
v.push_back(word(tmp.substr(0, pos), stoi(tmp.substr(pos + 1))));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if (pos1 != s.size()) {
tmp = s.substr(pos1, pos2 - pos1);
pos = tmp.find(':');
v.push_back(word(tmp.substr(0, pos), stoi(tmp.substr(pos + 1))));
}
}
int main() {
string str;
while (cin >>str) {
auto pos = str.find('@');
string str1, str2;
str1 = str.substr(0, pos);
str2 = str.substr(pos + 1);
//cout << str1 << " " << str2 << endl;
vector<word> all_vec;
splitString(str1, all_vec, ",");
vector<word> used_vec;
splitString(str2, used_vec, ",");
map<string, int> m;
for (auto it : used_vec) {
m[it.str] = it.cnt;
}
string res;
for (int i = 0; i < all_vec.size(); ++i) {
if (m.find(all_vec[i].str) != m.end())
all_vec[i].cnt -= m[all_vec[i].str];
if (all_vec[i].cnt>0) {
res += all_vec[i].str + ":" + to_string(all_vec[i].cnt) + ",";
}
}
if (!res.empty() && res[res.size() - 1] == ',')
res = res.substr(0, res.size()-1);
cout << res << endl;
}
return 0;
}
/*
a:3,b:5,c:2@a:1,b:2
*/
查看原帖
点赞 1
相关推荐
牛客热帖
更多
正在热议
更多
# 简历第一个项目做什么 #
4255次浏览 69人参与
# 租房找室友 #
58151次浏览 239人参与
# MiniMax求职进展汇总 #
1539次浏览 25人参与
# 实习的你做了哪些离谱的工作 #
5444次浏览 83人参与
# 工作压力大,你会干什么? #
6402次浏览 182人参与
# 参加哪些竞赛对找工作有帮助? #
5166次浏览 106人参与
# AI让你的思考变深了还是变浅了? #
2372次浏览 77人参与
# 找实习记录 #
13520次浏览 262人参与
# 如果不上班,你会去做什么 #
3566次浏览 171人参与
# 携程工作体验 #
20633次浏览 78人参与
# 邪修省钱套路 #
4312次浏览 158人参与
# 学历对求职的影响 #
587614次浏览 4003人参与
# 为了入行xx岗,我学了__ #
2992次浏览 49人参与
# 我的付费上班经历 #
8241次浏览 138人参与
# 一上班就想____,这正常吗? #
13882次浏览 143人参与
# 如果再来一次,你还会选择这个工作吗? #
779519次浏览 6261人参与
# 职场上哪些行为很加分? #
314262次浏览 3549人参与
# 如何KTV领导 #
83352次浏览 525人参与
# 产品实习,你更倾向大公司or小公司 #
193644次浏览 2074人参与
# 实习打杂,要跑路吗 #
56215次浏览 336人参与
# 你们公司哪个部门最累? #
37489次浏览 255人参与
