wangkai0351
2019-08-07 21:11:29 +08:00
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include <string.h>
using namespace std;
vector<string> split(const string &str,const string &pattern)
{
//const char* convert to char*
char * strc = new char[strlen(str.c_str())+1];
strcpy(strc, str.c_str());
vector<string> resultVec;
char* tmpStr = strtok(strc, pattern.c_str());
while (tmpStr != NULL)
{
resultVec.push_back(string(tmpStr));
tmpStr = strtok(NULL, pattern.c_str());
}
delete[] strc;
return resultVec;
}
int main(void)
{
string s;
while(cin>>s)
{
string s1;
string s2;
size_t at_pos = s.find('@');
//cout << "at_pos = " << at_pos << endl;
if(at_pos == s.size()-1)
{
for (int i = 0; i < s.size()-1; ++i) {
cout << s[i];
}
cout << endl;
break;
}
else
{
s1 = s.substr(0,at_pos);
s2 = s.substr(at_pos+1,s.size());
//cout << s1 << endl;
//cout << s2 << endl;
}
//分别处理 s1,s2
map<char,int> um1;
map<char,int> um2;
//s1 按照逗号分割
vector<string> v1;
v1 = split(s1,",");
for(auto e:v1)
{
int i;
char c;
char c_;
stringstream ss(e);
ss >> c >> c_ >> i;
//cout << "c = " << c << " i = " << i << endl;
um1[c] = i;
}
//s2 按照逗号分割
vector<string> v2;
v2 = split(s2,",");
for(auto e:v2)
{
int i;
char c;
char c_;
stringstream ss(e);
ss >> c >> c_ >> i;
//cout << "c = " << c << " i = " << i << endl;
um2[c] = i;
}
string res;
for(auto e:um1)
{
res += e.first;
res += ":";
res += to_string(e.second-um2[e.first]);
res += ",";
}
for (int j = 0; j < res.size()-1; ++j) {
cout << res[j];
}
cout << endl;
}
return 0;
}
//a:3,b:5,c:1@
//a:3,b:5,c:2@a:1,b:2