#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
相关推荐
带鱼吃猫几秒前
C++ 智能指针全解析:从 RAII 到自定义删除器的内存管理艺术R6bandito_3 分钟前
自实现FLASH读取函数中的隐式类型转换bug踩坑记录memcpy05 分钟前
LeetCode 1208. 尽可能使字符串相等【不定长滑窗,字符串】1497阿Y加油吧7 分钟前
LeetCode 二叉树双王炸!二叉树展开为链表 + 前序 + 中序还原二叉树|小白递归一把过AI科技星10 分钟前
全球AI信息场(信息网)基础理论与数学建模研究(乖乖数学)汉克老师15 分钟前
GESP2024年12月认证C++三级( 第一部分选择题(9-15))云中飞鸿17 分钟前
qt中显示日志的一般是哪个控件?仟濹18 分钟前
【算法打卡day37(2026-04-04 周六)】DFS专项训练4-枚举专项训练 1-全部是蓝桥杯真题汀、人工智能22 分钟前
12 - 内置函数:Python的瑞士军刀梦游钓鱼25 分钟前
虚继承实现原理详解及案例