-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2138.cpp
More file actions
42 lines (31 loc) · 756 Bytes
/
2138.cpp
File metadata and controls
42 lines (31 loc) · 756 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
#include<iostream>
#include<vector>
std::vector<std::string> divideString(std::string s, int k, char fill) {
std::vector<std::string> str;
std::string n_str;
int size = s.size();
for(int i = 0; i < size; ++i) {
n_str += s[i];
if(n_str.size() == k) {
str.push_back(n_str);
n_str.clear();
}
}
if(!n_str.empty()) {
while(n_str.size() != k) {
n_str += fill;
}
str.push_back(n_str);
}
return str;
}
int main() {
std::string s = "abcdefghij";
int k = 3;
char fill = 'x';
std::vector<std::string> str = divideString(s, k, fill);
for(std::string& s : str) {
std::cout << s << " ";
}
std::cin.get();
}