-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber13.cpp
More file actions
43 lines (35 loc) · 945 Bytes
/
problemnumber13.cpp
File metadata and controls
43 lines (35 loc) · 945 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
#include<iostream>
#include<algorithm>
#include<vector>
#include<array>
#include <string>
using namespace std;
//function to reverse a string while maintaining the spaces (if any) in their original place.
string solve(string s) {
string words;
for (int i = s.length() - 1; i >= 0; i--)
{
if (s[i] != ' ')
{
words += s[i];
}
if (s[words.length()] == ' ')
{
words += ' ';
}
}
return words;
}
int main() {
cout << solve("your code rocks");
return 0;
}
/*In this Kata, we are going to reverse a string while maintaining the spaces (if any) in their original place.
For example:
solve("our code") = "edo cruo"
-- Normal reversal without spaces is "edocruo".
-- However, there is a space at index 3, so the string becomes "edo cruo"
solve("your code rocks") = "skco redo cruoy".
solve("codewars") = "srawedoc"
More examples in the test cases. All input will be lower case letters and in some cases spaces.
Good luck!*/