Chat Server's Outgoing Traffic
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93359#problem/A (456321)
http://codeforces.com/problemset/problem/5/A
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
+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate
9
+Mike
-Mike
+Mike
Mike:Hi I am here
-Mike
+Kate
-Kate
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的更多相关文章
- 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 ...
- CodeForces.5A Chat Server's Outgoing Traffic
Chat Server's Outgoing Traffic 点我挑战提目 考察点 模拟 字符串 Time Mem Len Lang 30 0 543 c++ 题意分析 给出类似一个群的即时通讯系统, ...
- [CareerCup] 8.7 Chat Server 聊天服务器
8.7 Explain how you would design a chat server. In particular, provide details about the various bac ...
- 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 ...
- 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 ...
- Linux 网络流量查看 Linux ip traffic monitor
Network monitoring on Linux This post mentions some linux command line tools that can be used to mon ...
- 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 ...
- Node聊天程序实例06:server.js
作者:vousiu 出处:http://www.cnblogs.com/vousiu 本实例参考自Mike Cantelon等人的<Node.js in Action>一书. server ...
- 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 ...
随机推荐
- ICE中间件相关
Ice 是 网络通信引擎 Internet Communications Engine 的简称,是ZeroC开发的一个面向对象的中间件平台.它提供了面向对象的远程过程调用.网格计算和发布/订阅功能,并 ...
- TEXT 15 A text a day...
TEXT 15 A text a day... Mar 24th 2006 From The Economist print edition The medical uses of mobile ph ...
- Haskell语言学习笔记(59)Bitraversable
Bitraversable class (Bifunctor t, Bifoldable t) => Bitraversable t where bitraverse :: Applicativ ...
- win10磁盘碎片整理
如果我们想要加快win10系统运行速度的话,就需要定期整理碎片才可以,减少卡顿,提高性能. 一:注意事项 固态硬盘用户千万不要使用‘磁盘碎片整理功能’,因为使用的技术不一样,使用window自带的该功 ...
- mysql异常
一.Can't connect to MySQL server on 'localhost' (10061)翻译:不能连接到 localhost 上的mysql分析:这说明“localhost”计算机 ...
- Redis的简介
Redis 简介 Redis 是一个高性能的key-value数据库.支持复杂的数据结构,支持持久化,支持主从集群,支持高可用,支持较大的value存储... Redis是一个nosql,非关系型数据 ...
- Openvpn 日常问题解决
一.Openven的在windows系统下的使用: 1.Openven客户端2.2.0:http://pan.baidu.com/s/1sjJij4T 安装好客户端软件后,将服务器下发的证书和配置文件 ...
- rubber
rubber - 必应词典 美['rʌbər]英['rʌbə(r)] n.橡胶:橡皮:黑板擦 v.涂橡胶于…:〈美俚〉同“rubberneck” 网络橡皮擦:胶皮:橡皮轮胎 变形复数:rubbers:
- C++ 模板的全特化与偏特化
模板为什么要特化,因为编译器认为,对于特定的类型,如果你能对某一功能更好的实现,那么就该听你的. 模板分为类模板与函数模板,特化分为全特化与偏特化.全特化就是限定死模板实现的具体类型,偏特化就是如果这 ...
- thinkphp下多语言
这里指定2种语言 ,zh-cn 和 zh-tw 1.在配置文件中写入 'LANG_SWITCH_ON' => true, // 开启语言包功能 'LANG_AUTO_DETECT' => ...