-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2109.cpp
More file actions
34 lines (24 loc) · 697 Bytes
/
2109.cpp
File metadata and controls
34 lines (24 loc) · 697 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
#include <iostream>
#include <vector>
#include <string>
std::string addSpaces(std::string s, std::vector<int>& spaces) {
std::vector<std::string> vec;
std::string str = "";
vec.push_back(s.substr(0, spaces[0]));
vec.push_back(" ");
for (int i = 1; i < spaces.size(); ++i) {
vec.push_back(s.substr(spaces[i - 1], spaces[i] - spaces[i - 1]));
vec.push_back(" ");
}
vec.push_back(s.substr(spaces.back()));
for (const std::string& st : vec) {
str += st;
}
return str;
}
int main() {
std::string s = "LeetcodeHelpsMeLearn";
std::vector<int> spaces = { 8, 13, 15 };
std::cout << addSpaces(s, spaces);
return 0;
}