A. Chat Server's Outgoing Traffic

题目连接:

http://www.codeforces.com/contest/5/problem/A

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 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.

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:

+ for 'Add' command.

- for 'Remove' command.

<sender_name>:<message_text> for 'Send' command.

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

Sample Output

9

Hint

题意

有一个聊天室

有三种操作:

1.+ xxx 进来一个人

2.- xxx 出去一个人

3.xxx:xxxxx xxx对着所有人说xxxxx,然后这个会对所有人发送一个长度为l的信息。

问你一共发了多长的信息。

题解:

其实根本不用管究竟是谁进来,谁出去。

反正我只关注人数嘛。

代码

#include<bits/stdc++.h>
using namespace std;
int a,b;
string s; int main()
{
while(getline(cin,s))
{
if(s[0]=='+')a++;
else if(s[0]=='-')a--;
else b+=a*(s.size()-s.find(':')-1);
}
cout<<b<<endl;
}

Codeforces Beta Round #5 A. Chat Server's Outgoing Traffic 水题的更多相关文章

  1. Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题

    B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...

  2. Codeforces Beta Round #9 (Div. 2 Only) A. Die Roll 水题

    A. Die Roll 题目连接: http://www.codeforces.com/contest/9/problem/A Description Yakko, Wakko and Dot, wo ...

  3. Codeforces Beta Round #3 A. Shortest path of the king 水题

    A. Shortest path of the king 题目连接: http://www.codeforces.com/contest/3/problem/A Description The kin ...

  4. CodeForces.5A Chat Server's Outgoing Traffic

    Chat Server's Outgoing Traffic 点我挑战提目 考察点 模拟 字符串 Time Mem Len Lang 30 0 543 c++ 题意分析 给出类似一个群的即时通讯系统, ...

  5. Chat Server's Outgoing Traffic

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93359#problem/A (456321) http://codeforces.com ...

  6. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  7. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  8. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  9. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

随机推荐

  1. Skipping 'Android SDK Tools, revision 24.0.2'; it depends on 'Android SDK Platform-tools, revision 20' which was not installed.

    前几天,同事问我eclipse android sdk怎么不能更新. 更新界面是显示(mirrors.neusoft.edu.cn:80),但是不能更新. 问题描述如下: URL not found: ...

  2. git push multiple repo

    git remote add xxx https://git.github.com

  3. (5)剑指Offer之栈变队列和栈的压入、弹出序列

    一 用两个栈实现队列 题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 问题分析: 先来回顾一下栈和队列的基本特点: 栈:后进先出(LIFO) 队列: ...

  4. 树莓派开发系列教程3--ssh、vnc远程访问

    注意:树莓派系列的3篇文章里面的图片因为博客转移过程丢失了,非常抱歉 前言 远程访问有很多种方式可以实现.比如ssh.telnet.ftp.samba.远程桌面等等,各有优缺点.本文主要以ssh和远程 ...

  5. python3.x的HTMLTestRunner.py文件

    """A TestRunner for use with the Python unit testing framework. Itgenerates a HTML re ...

  6. C++——sort和stable_sort的若干区别

    版权声明:本文系作者原创,转载请注明出处. C++中sort和stable_sort的区别: sort是快速排序实现,因此是不稳定的:stable_sort是归并排序实现,因此是稳定的: 对于相等的元 ...

  7. Linux命令参数处理 shell脚本函数getopts

    getopts 命令 用途 处理命令行参数,并校验有效选项. 语法 getopts 选项字符串 名称 [ 参数 ...] 描述 getopts 的设计目标是在循环中运行,每次执行循环,getopts ...

  8. leetcode 之Remove Duplicates from Sorted Array(2)

    描述    Follow up for ”Remove Duplicates”: What if duplicates are allowed at most twice?    For exampl ...

  9. Perl 连接Oracle 出现OCI missing的问题及解决

    问题描述 新申请了一个虚拟机操作系统: Win Server 2008, 64位 , 8核, 16G Memory 上 http://www.activestate.com/activeperl 下载 ...

  10. LeetCode679. 24 Game

    You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated ...