聊天服务器传出流量|断续器 (jxnu.edu.cn)https://acs.jxnu.edu.cn/problem/CF5A
描述:
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:
Polycarp正在致力于一个新的项目叫做“Polychat”。他决定遵顼IT行业的趋势,这个项目也应该包含聊天。为了达到这一目的,Polycard在他的笔记本电脑前花费了几个小时,提供了3种方式:
- 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).
- 包含一个人交流(“Add”方式)。
- 从聊天中删除某人(“Remove”方式)。
- 将信息从一个人发给另一个正在聊天的人(“Send”方式)。
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 l bytes 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.
现在Polycard要找到服务器在处理一种方式时所产生的流量。
Polycard知道聊天服务不会给“Add”和“Remove”方式计算流量。处理"发送"命令时,服务器向聊天的每个参与者发送 l 字节,其中 l 是消息的长度。
因为Polycard没有时间,所以他请你来帮忙。
输入:
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:
输入文件将包含不超过100个命令,每个命令占一行。每行不超过100个字母。命令格式如下所示。
- +<name> for 'Add' command.
- -<name> for 'Remove' command.
- <sender_name>:<message_text> for 'Send' command.
- +<name>表示“Add”命令。
- -<name>表示“Remove”命令。
- <sender_name>:<message_text> 表示 'Send' 命令。
<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.
<name>和<sender_name>是拉丁字母和数字的非空序列。<message_text>可以包含字母、数字和空格,但不能以空格开头或结尾。<message_text>可以是空行。
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.
可以保证,所有数据是正确的。可以保证,输入数据是正确的,即如果聊天中已有具有此类名称的人,则不会有"添加"命令,如果聊天中没有具有此类名称的人,则不会有"删除"命令等。
所有名称区分大小写。
输出:
Print a single number — answer to the problem.
输出一个数字——回答问题。
样例输入:
+Mike Mike:hello +Kate +Dmitry -Dmitry Kate:hi -Kate
样例输出:
9
样例输入:
+Mike -Mike +Mike Mike:Hi I am here -Mike +Kate -Kate
样例输出:
14