-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplitStrings.cpp
More file actions
51 lines (46 loc) · 1.17 KB
/
SplitStrings.cpp
File metadata and controls
51 lines (46 loc) · 1.17 KB
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
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <sstream>
#include <climits>
using namespace std;
vector<string> solution(const string& s) {
vector<string> result;
string str = s;
if (str.size() % 2 != 0) {
str += '_';
}
for (size_t i = 0; i < str.size(); i += 2) {
result.push_back(str.substr(i, 2));
}
return result;
}
int main()
{
vector<string> result = solution("abc");
for (int i = 0; i < result.size(); i++)
{
cout << result[i];
}
return 0;
}
/*Description:
Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').
Examples:
* 'abc' => ['ab', 'c_']
* 'abcdef' => ['ab', 'cd', 'ef']
Regular Expressions
Strings
Algorithms*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU