题目链接如下,不过多赘述
http://codeforces.com/problemset/problem/5/A
在做这道题的过程中,应该注意的是有关String类中几个函数的用法
getline函数
格式:getline(input, str, delim)
其中:
input | 获取数据来源的流 |
str | 放置数据的目标string |
delim | 分隔字符 |
find函数
格式: str.find( charT ch / CharT* s, pos, count )
其中:
str | 要搜索的 string |
pos | 开始搜索的位置 |
count | 要搜索的子串长度 |
s | 指向要搜索的字符串的指针 |
ch | 要搜索的字符 |
思路极其简单,直接贴代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int info=0; //总流量数
int sump=0; //总人数
string text;
while(getline(cin,text,'\n'))
{
if(text[0]=='+')
{
sump++;
}
else if(text[0]=='-')
{
sump--;
}
else
{
int key=text.find(':',0);
info+=(text.size()-key-1)*sump;
}
}
cout<<info<<endl;
return 0;
}
参考引用:
https://blog.csdn.net/mig_davidli/article/details/8255052