#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
相关推荐
yunyun3212317 小时前
嵌入式C++驱动开发Storynone17 小时前
【Day29】LeetCode:62. 不同路径,63. 不同路径 II,343. 整数拆分,96. 不同的二叉搜索树小O的算法实验室17 小时前
2025年SEVC SCI2区,基于强化学习辅助粒子群算法的污水处理厂进水流量估算及出水调度问题研究,深度解析+性能实测左左右右左右摇晃17 小时前
Java笔记 —— 值传递与“引用传递”chushiyunen17 小时前
python语法-继承、方法命名、单例等2301_7854035217 小时前
代码随想录算法营总结yeflx17 小时前
三维空间坐标转换早期笔记沐知全栈开发17 小时前
Chart.js 饼图详解码云数智-大飞17 小时前
迈向 99.99%:高可用系统架构的哲学与实战Amnesia0_017 小时前
类型转换和特殊类