-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber14.cpp
More file actions
33 lines (27 loc) · 987 Bytes
/
Copy pathproblemnumber14.cpp
File metadata and controls
33 lines (27 loc) · 987 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<algorithm>
#include<vector>
#include<array>
#include <string>
using namespace std;
//function reverse the portion of that string between those two indices inclusive
string solve(string s, int a, int b) {
if (b < s.size())
{
reverse(s.begin() + a, s.begin() + b + 1);
}
else
{
reverse(s.begin() + a, s.end());
}
return s;
}
int main() {
cout << solve("FunctionalProgramming", 2, 15);
return 0;
}
/*In this Kata, you will be given a string and two indexes (a and b). Your task is to reverse the portion of that string between those two indices inclusive.
solve("codewars",1,5) = "cawedors" -- elements at index 1 to 5 inclusive are "odewa". So we reverse them.
solve("cODEWArs", 1,5) = "cAWEDOrs" -- to help visualize.
Input will be lowercase and uppercase letters only.
The first index a will always be lower that than the string length; the second index b can be greater than the string length. More examples in the test cases. Good luck!*/