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 ...
随机推荐
- 英语广播原声听力100篇MP3及听力原文
=============7.6================ Passage 031- 人工智能对人类的利与弊From a personal assistant, to doing searche ...
- pycharm ideavimrc设置备忘
文件存放位置 windows下 C:\Users\你的用户名\.ideavimrc 注:如果要映射pycharm 中的一些命令可以 在pycharm 中 edit->Macros->Sta ...
- 移去OleContainer的黑边框
//禁止双击打开word编辑 olecontainer1.AutoActivate := aaManual; //禁止右键菜单 olecontainer1.AutoVerbMenu := False; ...
- struts2的运行流程
流程: 1:url 提交到tomcat http://localhost/s2/firstAction 2:tomcat 根据工程名 去 webapps 文件夹下找到对应工程 3:找web.xml S ...
- centos7 /etc/profile /etc/bashrc
在/etc/profile中添加环境变量后,是使用source /etc/profile编译后只能在当前终端生效 重新开启一个终端后,该环境变量失效. 解决方法: 重启系统:reboot,问题解决 环 ...
- $.ajax dataType设置为json 回调函数不执行
请求方式如下: $.xpost = function (url, data) { return $.ajax({ url: url, type: "POST", dataType: ...
- SpringBoot application.yml logback.xml 多环境
启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 java -jar app.j ...
- Realm For Android详细教程
目录 1.Realm简介 2.环境配置 3.在Application中初始化Realm 4.创建实体 5.增删改查 6.异步操作 7.Demo地址(https://github.com/RaphetS ...
- 基于mysql全文索引的深入理解
最近要使用mysql的全文索引,一直没能成功,一个是只有MyISAM引擎支持,创建表时需要指定,而是需要对my.ini进行配置. 前言:本文简单讲述全文索引的应用实例,MYSQL演示版本5.5.24. ...
- hdoj3038(带权并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:对于给定的a1..an,通过询问下标x..y,给出a[x]+...+a[y],但给出的值可 ...