#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
相关推荐
ShineWinsu5 小时前
对于C++:类和对象的解析—下(第二部分)码农水水5 小时前
国家电网Java面试被问:TCP的BBR拥塞控制算法原理2013092416275 小时前
1968年 Hart, Nilsson, Raphael 《最小成本路径启发式确定的形式基础》A* 算法深度研究报告如何原谅奋力过但无声5 小时前
【力扣-Python-滑动窗口经典题】567.字符串的排列 | 424.替换后的最长重复字符 | 76.最小覆盖子串浮尘笔记5 小时前
Go语言临时对象池:sync.Pool的原理与使用咕噜咕噜啦啦6 小时前
Java期末习题速通BHXDML6 小时前
第七章:类与对象(c++)玄冥剑尊6 小时前
贪心算法进阶玄冥剑尊6 小时前
贪心算法深化 I52Hz1186 小时前
力扣73.矩阵置零、54.螺旋矩阵、48.旋转图像