#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
相关推荐
森林里的程序猿猿6 分钟前
并发设计模式222you15 分钟前
四个主要的函数式接口小O的算法实验室1 小时前
2026年KBS,赏金猎人优化算法+多无人机移动边缘计算与路径规划,深度解析+性能实测用户5671504710211 小时前
OpenClaw 记忆管理系统技术文档smchaopiao1 小时前
Python中字典与列表合并的问题与解决方法935961 小时前
练习题53-60霖大侠2 小时前
Wavelet Meets Adam: Compressing Gradients forMemory-Efficient Training敲代码的瓦龙2 小时前
Java?面向对象三大特性!!!2501_921649492 小时前
期货 Tick 级数据与基金净值历史数据 API 接口详解