Codeforces 5A

#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;
}


你可能感兴趣的:(Codeforces 5A)