發(fā)文章
發(fā)文工具
撰寫
網(wǎng)文摘手
文檔
視頻
思維導(dǎo)圖
隨筆
相冊
原創(chuàng)同步助手
其他工具
圖片轉(zhuǎn)文字
文件清理
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 > 《專業(yè)》
0條評論
發(fā)表
請遵守用戶 評論公約
c++實(shí)現(xiàn)split函數(shù)
劍指offer 50 構(gòu)建乘積數(shù)組
//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 版權(quán)聲明:著作權(quán)歸作者所有,商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處 前言。歸并排序法的實(shí)現(xiàn)思路有很...
opencv 截取輪廓中的圖像
我們很容易用findContours()函數(shù)將圖像中的輪廓提取出來,但是并沒有將輪廓所包圍的圖像輸出的函數(shù),以下是幾個有類似功能的函數(shù):cvima...
C++:實(shí)現(xiàn)split分割字符串
void split(const string& src, const string& separator, vector<string>& dest){ string str = src;#include <stdio.h>#include <stdlib.h>#include <string.h&...
[機(jī)器學(xué)習(xí)]基于OpenCV實(shí)現(xiàn)最簡單的數(shù)字識別
IplImage preprocessing(IplImage* img, int w, int h){ ... bb = findBoundingBox(img);cvGetSubRect(img, &data, cvRec...
[bzoj4311] 向量
你要維護(hù)一個向量集合,支持以下操作:1.插入一個向量 \((x,y)\)2.刪除插入的第 \(i\) 個向量3.查詢當(dāng)前集合與 \((x,y)\) 點(diǎn)積的最大值是多少。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()
微信掃碼,在手機(jī)上查看選中內(nèi)容