codeforces Round5 A. Chat Server's Outgoing Traffic

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define ls rt<<1
#define rs ls1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle (l+r)>>1
#define eps (1e-9)
#define type int
#define clr_all(x,c) memset(x,c,sizeof(x))
#define clr(x,c,n) memset(x,c,sizeof(x[0])*(n+1))
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define M 100+5
int main(){
    int n=0,i,j,sum=0;
 char s[M];
    while(gets(s)){
  j=strlen(s);
  if(s[0]=='+')n++;
  else if(s[0]=='-')n--;
  else{
   i=0;
   while(s[i]!=':')i++;
   sum+=n*(j-i-1);
  }
 }
 printf("%d\n",sum);
    return 0;
}

你可能感兴趣的:(模拟,coderforce)