【每日练习】水题codeforce5A

题目链接如下,不过多赘述

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   要搜索的子串长度
指向要搜索的字符串的指针
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://zh.cppreference.com

https://blog.csdn.net/mig_davidli/article/details/8255052

      

          

      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值