-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopgninnipSMysdroW!.cpp
More file actions
52 lines (45 loc) · 1.19 KB
/
StopgninnipSMysdroW!.cpp
File metadata and controls
52 lines (45 loc) · 1.19 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
52
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <iostream>
using namespace std;
string spinWords(const string& str)
{
string result;
string word;
for (char cv : str)
{
if (cv == ' ')
{
if (word.length() >= 5)
{
reverse(word.begin(), word.end());
}
result += word + ' ';
word.clear();
}
else
{
word += cv;
}
}
if (word.length() >= 5) {
std::reverse(word.begin(), word.end());
}
result += word;
return result;
}
int main() {
cout << spinWords("Hey fellow warriors ");
return 0;
}
/*Description:
Write a function that takes in a string of one or more words, and returns the same string, but with all words that have five or more letters reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
Examples:
"Hey fellow warriors" --> "Hey wollef sroirraw"
"This is a test --> "This is a test"
"This is another test" --> "This is rehtona test"
Strings
Algorithms*/