首页 / includeltiostreamgt
#

includeltiostreamgt

#
361次浏览 2299人互动
此刻你想和大家分享什么
热门 最新
今天写了一个很蹩脚的算法(实现过程有些复杂,也可能有一些bug,需要优化):输入一个字符集如"a:3,b:5,C:12,d:100@a:1,b:5,C:9",@前属于全字符集,后面是使用字符集,数字部分代表使用数量;字母区分大小写,字符集间用逗号隔开。要求输出剩余可用字符集如上结果为"a:3,b:0,C:3"实现代码如下:#include <iostream>(720)#include <vector>using namespace std;vector<string> cutStr(string str){    int len = static_cast<int>(str.size());    vector<string> ch_set(str.size());    int start=0;    int n=0;    for(int i=0;i<len;++i){        if(str[i]==,){            ch_set[n] = str.substr(start,i-start);            start = i+1;            n++;        }        if(i==len-1){            ch_set[n] = str.substr(start,i-start+1);        }    }    ch_set.resize(n+1);    return ch_set;}
2020-07-27
在牛客打卡1天,今天也很努力鸭!
点赞 评论 收藏
转发
玩命加载中
牛客网
牛客企业服务