-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_into_words.cpp
More file actions
54 lines (44 loc) · 940 Bytes
/
Copy pathsplit_into_words.cpp
File metadata and controls
54 lines (44 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
vector<string> SplitIntoWords(const string &s)
{
auto it_begin = s.begin();
auto it_end = it_begin;
vector<string> result;
while (it_begin != s.end())
{
it_end = find(it_begin, s.end(), ' ');
if (it_begin != it_end)
{
result.push_back({it_begin, it_end});
}
if (it_end != s.end())
{
it_begin = it_end + 1;
}
else
{
break;
}
}
return result;
}
int main()
{
string s = " C Cpp Java Python ";
vector<string> words = SplitIntoWords(s);
cout << words.size() << " ";
for (auto it = begin(words); it != end(words); ++it)
{
if (it != begin(words))
{
cout << "/";
}
cout << *it;
}
cout << endl;
return 0;
}