A. Chat Server's outgoing traffic

Source: Internet
Author: User
Time limit per test

1 second

Memory limit per test

64 megabytes

Input

Standard Input

Output

Standard output

Polycarp is working on a new project called "polychat ". following modern tendencies in it, he decided, that this project shoshould 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 ( 'delete' 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 special set of commands.

Polycarp knows that chat server sends no traffic for 'add' and 'remove 'commands. When 'send' command is processed, server sendsLBytes
Each participant ipant of the chat, whereLIs 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'Delete'Command.
  • <Sender_name >:< message_text>For'Send'Command.

and is
A non-empty sequence of Latin letters and digits. can contain letters, digits and spaces, but can't start or end with a space. 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'Delete'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 test (s) Input
 
+ Mikemike: Hello + Kate + Dmitry-dmitrykate: Hi-Kate
Output
 
9
Input
+ Mike-Mike + mikemike: Hi I am here-Mike + Kate-Kate
Output
 
14

Solution Description: first, count the number of people involved in the conversation, then find the number of letters to be sent (including punctuation and space), and then multiply the number to calculate the sum.

 # include 
  
    # include 
   
     # include 
    
      # include 
     
       # include 
      
        using namespace STD; int main () {int I = 0, c = 0, S = 0; char a [102]; while (gets ()! = NULL) {if (a [0] = '+') {C ++;} else if (a [0] = '-') {c --;} else {I = 0; while (A [I]! = ':') {I ++;} s + = (strlen (a)-i-1) * C ;}} printf ("% d \ n", S ); return 0 ;}
      
     
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.