#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
相关推荐
JieE2122 天前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断JieE2122 天前
LeetCode 56. 合并区间|超清晰 JS 图解思路,面试高频区间题Jack203 天前
HarmonyOS开发中错误处理策略:网络异常统一处理小小杨树3 天前
读懂色彩:拍照调色不再难JieE2124 天前
LeetCode 226. 翻转二叉树|JS 递归超详细拆解,二叉树入门经典题JieE2124 天前
LeetCode 104. 二叉树的最大深度|递归思路超详细拆解vivo互联网技术4 天前
CVPR 2026 | 全新强化学习框架 BeautyGRPO:重塑真实人像Darling噜啦啦4 天前
列表转树算法深度解析:从 Map 到 Reduce 的两种实现,面试高频考点clint4564 天前
C++进阶(1)——前景提要