http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93359#problem/A (456321)

http://codeforces.com/problemset/problem/5/A

Chat Server's Outgoing Traffic

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:

  • Include a person to the chat ('Add' command).
  • Remove a person from the chat ('Remove' command).
  • Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send'command).

Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.

Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends lbytes to each participant of the chat, where l is the length of the message.

As Polycarp has no time, he is asking for your help in solving this problem.

Input

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:

  • +<name> for 'Add' command.
  • -<name> for 'Remove' command.
  • <sender_name>:<message_text> for 'Send' command.

<name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.

It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.

All names are case-sensitive.

Output

Print a single number — answer to the problem.

Sample Input

Input
+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate
Output
9
Input
+Mike
-Mike
+Mike
Mike:Hi I am here
-Mike
+Kate
-Kate
Output
14

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std; #define N 210 int main()
{
int k=, sum=;
char s[N]; while(gets(s))
{
if(s[]=='+') k++;
else if(s[]=='-') k--;
else
{
int i=;
while(s[i]!=':') i++; int len = strlen(s);
sum += (len-i-)*k;
}
} printf("%d\n", sum);
return ;
}

Chat Server's Outgoing Traffic的更多相关文章

  1. Codeforces Beta Round #5 A. Chat Server's Outgoing Traffic 水题

    A. Chat Server's Outgoing Traffic 题目连接: http://www.codeforces.com/contest/5/problem/A Description Po ...

  2. CodeForces.5A Chat Server's Outgoing Traffic

    Chat Server's Outgoing Traffic 点我挑战提目 考察点 模拟 字符串 Time Mem Len Lang 30 0 543 c++ 题意分析 给出类似一个群的即时通讯系统, ...

  3. [CareerCup] 8.7 Chat Server 聊天服务器

    8.7 Explain how you would design a chat server. In particular, provide details about the various bac ...

  4. tc: Linux HTTP Outgoing Traffic Shaping (Port 80 Traffic Shaping)(转)

    原文:https://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic/ I‘ve 10Mbps ...

  5. the Linux Kernel: Traffic Control, Shaping and QoS

    −Table of Contents Journey to the Center of the Linux Kernel: Traffic Control, Shaping and QoS 1 Int ...

  6. Linux 网络流量查看 Linux ip traffic monitor

    Network monitoring on Linux This post mentions some linux command line tools that can be used to mon ...

  7. How To Set Up an OpenVPN Server on Ubuntu 14.04

    Prerequisites The only prerequisite is having a Ubuntu 14.04 Droplet established and running. You wi ...

  8. Node聊天程序实例06:server.js

    作者:vousiu 出处:http://www.cnblogs.com/vousiu 本实例参考自Mike Cantelon等人的<Node.js in Action>一书. server ...

  9. Making your local server accessible from anywhere

    In reality you probably don’t want to host you websites on your local computer unless you have a ver ...

随机推荐

  1. devel包

    devel 包主要是供开发用,至少包括以下2个东西:1. 头文件2. 链接库有的还含有开发文档或演示代码. 以 glib 和 glib-devel 为例: 如果你安装基于 glib 开发的程序,只需要 ...

  2. MySql重复查询

    MYSQL查询重复记录的方法很多,下面就为您介绍几种最常用的MYSQL查询重复记录的方法,希望对您学习MYSQL查询重复记录方面能有所帮助. 1.查找表中多余的重复记录,重复记录是根据单个字段(peo ...

  3. Ansible 书写我的playbook

    mysql 创建数据库 - hosts: localhost  remote_user: root  tasks: - name: test mysql    mysql_db:      name: ...

  4. 获取Activity中得到焦点的EditText

    Android Activity中获取当前焦点的控件,自动化输入EditText 获取焦点的view对象 View view=getWindow().getDecorView().findFocus( ...

  5. idea 码云 项目上传

    1.点击导航栏 VCS -> Import into Version Control -> 托管项目到码云 2.输入码云帐号密码,点击login. 3.勾选private,点击托管按钮. ...

  6. Python实现的常用排序方法

    1.冒泡排序,相邻位置比较大小,将比较大的(或小的)交换位置 def maopao(a):     for i in range(0,len(a)):         for j in range(0 ...

  7. 关于easyui-datagrid数据表格, 分页取出数据

    在制作数据表格的时候有一个这样的属性, pagination是否显示分页列表, 分页显示的时候需要分别从数据库中取数据, 每页显示几行, 即只从数据库取出几行数据来显示, 具体代码如下 1, 显示页面 ...

  8. DOS 命令集锦——最常用命令

    一. 常用命令: cd 改变当前目录   sys 制作DOS系统盘 (电脑入门到精通网 www.58116.cn) copy 拷贝文件  del 删除文件 deltree 删除目录树    dir 列 ...

  9. REVERSE!REVERSE!REVERSE!

    形式汇总: 206. Reverse Linked List 92. Reverse Linked List II:Given a string and an integer k, you need ...

  10. HashMap的hash冲突解决方案

    Hash函数 非哈希表的特点:关键字在表中的位置和它之间不存在一个确定的关系,查找的过程为给定值一次和各个关键字进行比较,查找的效率取决于和给定值进行比较的次数. 哈希表的特点:关键字在表中位置和它之 ...