关注
#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
相关推荐
点赞 评论 收藏
分享
03-11 19:11
The University of New South Wales 算法工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你感受到金三银四了嘛? #
69472次浏览 611人参与
# 美团笔试 #
694948次浏览 4623人参与
# 虽然0面试,但今天___,夸夸自己 #
8543次浏览 172人参与
# 米哈游笔试 #
550323次浏览 1087人参与
# 春招 / 实习投递,你最焦虑的一件事 #
52343次浏览 1021人参与
# vivo笔试 #
12951次浏览 122人参与
# 27届实习投递记录 #
821次浏览 22人参与
# AI岗位暴涨12倍,你会转AI赛道吗? #
4435次浏览 90人参与
# 今天你投了哪些公司? #
142081次浏览 2575人参与
# 金三银四,你的春招进行到哪个阶段了? #
18577次浏览 254人参与
# 运营每日一题 #
127394次浏览 900人参与
# 美团秋招笔试 #
194602次浏览 1065人参与
# 小米编程考试 #
31159次浏览 151人参与
# 字节7000实习来了,你投了吗? #
4231次浏览 20人参与
# 刚工作的你,踩过哪些坑? #
5869次浏览 136人参与
# AI项目实战 #
6419次浏览 306人参与
# 小米笔试 #
138986次浏览 994人参与
# 找工作,你都让AI帮你做什么? #
6558次浏览 213人参与
# 软件开发春招备战日记 #
92977次浏览 611人参与
# vivo求职进展汇总 #
277774次浏览 1558人参与