#include<iostream>
#include<bits/stdc++.h>
using namespace std;
vector<string> split(string s) {
int len = s.length();
int i(0);
string ans= "", temp;
vector<string> res;
while(i<len) {
temp = "";
while(i<len&&s[i]==' ') {i++;}
while(i<len&&s[i]!=' ') {
temp += s[i++];
}
res.push_back(temp);
}
return res;
}
int main(int argc, char** argv) {
string s = "dog cat cat dog";
vector<string> res;
res = split(s);
cout<<"字符串单词数量 "<<res.size()<<"------"<<endl;
for(auto i:res) {
cout<<i<<endl;
}
return 0;
}
字符串分割单词C++
IRON_MAN_LEVEL12023-11-10 20:24
相关推荐
mask哥2 分钟前
力扣算法java实现汇总整理(上)2zcode5 分钟前
运动模糊图像复原的MATLAB仿真与优化袁雅倩199716 分钟前
当吸尘器、筋膜枪都用上Type-C,供电方案该怎么选?浅谈PD取电芯片ECP5702的应用如果'\'真能转义说44 分钟前
OOXML 文档格式剖析:哈希、ZIP结构与识别Aaswk1 小时前
Java Lambda 表达式与流处理万邦科技Lafite1 小时前
京东item_get接口实战案例:实时商品价格监控全流程解析王老师青少年编程2 小时前
csp信奥赛C++高频考点专项训练之字符串 --【子串查找】:[NOIP 2009 提高组] 潜伏者Cyber4K2 小时前
【Python专项】进阶语法-系统资源监控与数据采集(1)梦梦代码精2 小时前
BuildingAI 上部署自定义工作流智能体:5 个实用技巧初願致夕霞2 小时前
基于系统调用的Linux网络编程——UDP与TCP