发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
#include <iostream>
02
#include <iterator>
03
#include <string>
04
#include <vector>
05
06
using
namespace
std;
07
08
vector<string> split(
const
string& s) {
09
10
vector<string> ret;
11
typedef
string::size_type string_size;
12
string_size i = 0;
13
14
// invariant: we have processed characters [original value of i, i)
15
while
(i != s.size()) {
16
17
// ignore leading blanks
18
// invariant: chartacters in range [original i, current i) are all spaces
19
(i !=s.size() &&
isspace
(s[i]))
20
++i;
21
22
// find end of next word
23
string_size j = i;
24
// invariant: none of the characters in rang [original j, current j) is a space
25
(j != s.size() && !
(s[j]))
26
++j;
27
28
// if we found some nonewithspace characters
29
if
(i != j) {
30
// copy from s starting at i and taking j - i chars
31
ret.push_back(s.substr(i, j - i));
32
i = j;
33
}
34
35
return
ret;
36
37
38
int
main() {
39
40
string s;
41
42
// read and split each line of input
43
(getline(cin, s)) {
44
vector<string> v = split(s);
45
46
// write eeach word in v
47
for
(vector<string>::size_type i = 0; i != v.size(); ++i)
48
cout << v[i] << endl;
49
50
51
system
(
"PAUSE"
);
52
0;
53
来自: mrjbydd > 《专业》
0条评论
发表
请遵守用户 评论公约
c++实现split函数
剑指offer 50 构建乘积数组
//B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]//从左到右算 B[i]=A[0]*A[1]*...*A[i-1]//从右到左算B[i]*=A[i+1]*...*A[n-1]class Solution {public: vector<int> multiply(const vector<in...
基本算法-归并排序
作者:翟天保Steven 版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处 前言。归并排序法的实现思路有很...
opencv 截取轮廓中的图像
我们很容易用findContours()函数将图像中的轮廓提取出来,但是并没有将轮廓所包围的图像输出的函数,以下是几个有类似功能的函数:cvima...
C++:实现split分割字符串
void split(const string& src, const string& separator, vector<string>& dest){ string str = src;#include <stdio.h>#include <stdlib.h>#include <string.h&...
[机器学习]基于OpenCV实现最简单的数字识别
IplImage preprocessing(IplImage* img, int w, int h){ ... bb = findBoundingBox(img);cvGetSubRect(img, &data, cvRec...
[bzoj4311] 向量
你要维护一个向量集合,支持以下操作:1.插入一个向量 \((x,y)\)2.删除插入的第 \(i\) 个向量3.查询当前集合与 \((x,y)\) 点积的最大值是多少。while(isdigit(ch)) x=x*10 ch-'''''...
C++字符串分割
void split(const char *s, vector<string> &strs, char delim =tail) { strs.将字符串s按照delim代表的字符分割,并且放入vector中。string str_temp;void split(const std::string &s,...
Python获取单个程序CPU使用情况趋势图
list1 = [1,2,3]list2 = [4,5,9]plt.plot(list1,list2)plt.show()
微信扫码,在手机上查看选中内容