-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path151.cpp
37 lines (35 loc) · 852 Bytes
/
151.cpp
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
#include <algorithm>
#include <gtest/gtest.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
string reverseWords(string s)
{
vector<string> words;
istringstream iss(s);
string word;
while (iss >> word) {
words.push_back(word);
}
reverse(words.begin(), words.end());
string result;
for (const auto &word : words) {
result += word + " ";
}
result.pop_back();
return result;
}
};
class Testing : public testing::Test {
public:
Solution s;
};
TEST_F(Testing, Case)
{
EXPECT_EQ(s.reverseWords("the sky is blue"), "blue is sky the");
EXPECT_EQ(s.reverseWords(" hello world "), "world hello");
EXPECT_EQ(s.reverseWords("a good example"), "example good a");
}