Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
int main(){
std::string line;
int users(0), total(0);
while(getline(std::cin, line)){
if(line[0] == '+'){++users;}
else if(line[0] == '-'){--users;}
else{total += users * (line.size() - line.find(':') - 1);}
}
std::cout << total << std::endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate
Output
9
Demonstration
Codeforces Solution -A. Chat Server's Outgoing Traffic-Solution in C, C++, Java, Python