#include<iostream>
#include<cstdio>
#include<string.h>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
const int maxn = 150;
char input[maxn];
string inputstr;
set<string> nameset;
int main(){
int cnt = 0;
while(getline(cin, inputstr)){
memset(input, 0, sizeof(input));
strcpy(input, inputstr.c_str());
if(input[0] == '+'){
string name = inputstr.substr(1);
nameset.insert(name);
}
else if(input[0] == '-'){
string name = inputstr.substr(1);
nameset.erase(name);
}
else{
int pos = inputstr.find_first_of(':');
string name = inputstr.substr(0, pos);
string message = inputstr.substr(pos + 1);
int tmpsize = nameset.size();
int messlen = message.length();
cnt += tmpsize * messlen;
}
}
cout << cnt << endl;
return 0;
}
转载于:https://my.oschina.net/u/1421373/blog/379424