#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
相关推荐
java 乐山6 分钟前
c 写一个文本浏览器(1)im_AMBER17 分钟前
Leetcode 105 K 个一组翻转链表sin_hielo20 分钟前
leetcode 1877windows_620 分钟前
MISRA C:2025 规则逐条分析睡不醒的kun37 分钟前
定长滑动窗口-基础篇(2)fie888944 分钟前
基于MATLAB的可见光通信(VLC)系统仿真小王努力学编程1 小时前
LangChain——AI应用开发框架(核心组件1)写代码的【黑咖啡】1 小时前
Python中的lxml:高效XML处理库庄小焱1 小时前
【机器学习】——房屋销售价格预测实战黎雁·泠崖1 小时前
Java字符串高阶:底层原理深剖+经典面试题全解