http://codeforces.com/contest/5
A
模拟题
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 11 12 int main(){ 13 std::ios::sync_with_stdio(false); 14 #ifndef ONLINE_JUDGE 15 freopen("1.txt","r",stdin); 16 #endif 17 set<string>se; 18 string str; 19 int i; 20 int ans=0; 21 while(getline(cin,str)){ 22 if(str.length()==0) break; 23 if(str[0]=='+'||str[0]=='-'){ 24 if(str[0]=='+'){ 25 str=str.substr(1); 26 se.insert(str); 27 } 28 else{ 29 str=str.substr(1); 30 se.erase(str); 31 } 32 } 33 else{ 34 for(i=0;i<str.length();i++){ 35 if(str[i]==':') break; 36 } 37 // cout<<i<<endl; 38 ans+=se.size()*(str.length()-1-i); 39 } 40 } 41 cout<<ans<<endl; 42 return 0; 43 }