Leetcode—2788. 按分隔符拆分字符串【简单】(stringstream的应用)

2023每日刷题(八十六)

Leetcode---2788. 按分隔符拆分字符串

实现代码

cpp 复制代码
class Solution {
public:
    vector<string> splitWordsBySeparator(vector<string>& words, char separator) {
        vector<string> res;
        for(auto word: words) {
            stringstream ss(word);
            string sub;
            while(getline(ss, sub, separator)) {
                if(!sub.empty()) {
                    res.push_back(sub);
                }
            }
        }
        return res;
    }
};

运行结果


之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
ValhallaCoder2 小时前
hot100-栈
数据结构·python·算法·
WW_千谷山4_sch7 小时前
洛谷B3688:[语言月赛202212]旋转排列(新解法:deque双端队列)
数据结构·c++·算法
Zachery Pole7 小时前
【代码随想录】二叉树
算法
漂流瓶jz7 小时前
UVA-11214 守卫棋盘 题解答案代码 算法竞赛入门经典第二版
c++·算法·dfs·aoapc·算法竞赛入门经典·迭代加深搜索·八皇后
浮生09197 小时前
DHUOJ 基础 88 89 90
算法
fpcc8 小时前
并行编程实战——CUDA编程的Enhancing Memory Allocation
c++·cuda
v_for_van8 小时前
力扣刷题记录7(无算法背景,纯C语言)
c语言·算法·leetcode
先做个垃圾出来………8 小时前
3640. 三段式数组 II
数据结构·算法
白太岁8 小时前
通信:(3) 高并发网络通信:epoll + 边沿触发 + 非阻塞 IO + tcp
c语言·网络·c++·网络协议·tcp/ip
楼田莉子9 小时前
C++项目:日志&&线程池
linux·c++·学习·visual studio code