CF5A.Chat Server's Outgoing Traffic
入门
通过率:0%
时间限制:1.00s
内存限制:64MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 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.
波利卡普正在开发一个名为“Polychat”的新项目。为了顺应 IT 行业的现代趋势,他决定在该项目中加入聊天功能。为实现这一目标,波利卡普在笔记本电脑前工作了数小时,实现了一个能够处理以下三类命令的聊天服务器:
- 将某人加入聊天(“Add” 命令);
- 将某人从聊天中移除(“Remove” 命令);
- 由某人向当前所有在线聊天成员(包括发送者本人)发送一条消息(“Send” 命令)。
现在,波利卡普希望计算出:服务器在处理某一特定命令序列时所产生的出站流量总量。
波利卡普已知,“Add” 和 “Remove” 命令不会产生任何网络流量。而当处理 “Send” 命令时,服务器会向聊天中的每一位参与者发送长度为 l 字节的数据,其中 l 是该消息的长度。
由于波利卡普时间紧迫,他请求你帮助解决这一问题。
输入格式
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:
- +
for 'Add' command. - -
for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
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.
输入文件包含不超过 100 条命令,每条命令独占一行。每行长度不超过 100 个字符。命令格式如下:
+<name>表示“添加”命令;\-<name>表示“移除”命令;<sender_name>:<message_text>表示“发送”命令。
其中 <name> 和 <sender_name> 是由拉丁字母和数字组成的非空字符串;<message_text> 可包含字母、数字和空格,但不能以空格开头或结尾;<message_text> 可以为空行。
保证输入数据合法:例如,不会对已在聊天室中的用户执行“添加”命令,也不会对不在聊天室中的用户执行“移除”命令等。
所有名称区分大小写。
输出格式
Print a single number — answer to the problem.
输出一个数字——即该问题的答案。
输入输出样例
输入#1
+Mike Mike:hello +Kate +Dmitry -Dmitry Kate:hi -Kate
输出#1
9
输入#2
+Mike -Mike +Mike Mike:Hi I am here -Mike +Kate -Kate
输出#2
14
输入解题思路,AI测评打分。不知道怎么写?