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 ...
随机推荐
- Java Magic. Part 1: java.net.URL
Java Magic. Part 1: java.net.URL @(Base)[JDK, url, magic, 黑魔法] 英文原文 转载请写明:原文地址 系列文章: -Java Magic. Pa ...
- bedtools简介及应用
1)背景处理基因组数据中,比较基因组不同区域,例如寻找overlap等,是一种基本的且常见的问题.虽然UCSC 中‘Table Browser’或者Galaxy可以用来处理,但是当这些工具面对大的数据 ...
- Maven国内镜像-阿里云
国外的maven下载速度堪忧,大部分国内网络访问都很慢国内的阿里云同样提供了maven的文件镜像使用:1.在maven的setting.xml加入下段代码即可使用阿里云的maven镜像 <mir ...
- Asp.net中判断是否是指定页面请求的代码示例
//获取请求网址,非法请求,返回主页 if (Request.UrlReferrer != null) { string requstUrl = Request.UrlReferrer.Absolut ...
- day1:vcp考试
Q1. An administrator wants to provide users restricted access. The users should only be able to perf ...
- iOS - OC - JSON 解析 - NSJSONSerialization
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- Web服务器和应用服务器简介
通俗的讲,Web服务器传送页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序可以调用(call)的方法(methods).确切一点,你可以说:Web服务器专门处理HTTP请求(reques ...
- php使用数组语法访问对象
有一个对象,不过希望能用数组的语法来读写数据,可以使用 实现SPL的ArrayAccess接口来解决. 使用场景:加载配置文件类.larvel框架加载配置文件就这利用数组来操作对象. 数组式访问Obj ...
- loadrunner12.5-vugen回放脚本提示:URL=“http://www.testclass.net/js/scripts.js”的常规连接当前无套接字 (16 不足) 可用,是什么意思呢?怎么理解呢?
会发生这个报错,是因为每个浏览器都有一个限制,检查哪个浏览器客户正在模拟, 通常只允许16个并发连接. 如果超过此超过接数,将显示该消息,通知您没有可用的连接. 而max connection的默认值 ...
- 设计模式之prototype(原型模型)
以我的理解原型模式的重点就几个字 用于克隆易变对象设计模式主要是为了解决new对象时的耦合问题,这是要克隆某个易变对象时只要直接传入要克隆的对象就可以实现克隆一下是我复制网上的一些代码 摘自<设 ...