#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
相关推荐
lly2024067 分钟前
组合模式(Composite Pattern)Billlly9 分钟前
ABC 453 个人题解玉树临风ives17 分钟前
atcoder ABC 452 题解游乐码27 分钟前
c#泛型约束Dontla39 分钟前
go语言Windows安装教程(安装go安装Golang安装)(GOPATH、Go Modules)chushiyunen39 分钟前
python rest请求、requestsfeifeigo12340 分钟前
基于马尔可夫随机场模型的SAR图像变化检测源码实现铁东博客1 小时前
Go实现周易大衍筮法三变取爻baidu_huihui1 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)南 阳1 小时前
Python从入门到精通day63