不能写main函数,你需要的是按照class Solution给的接口来实现它的一个成员函数
给一个参考答案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include
using namespace std;
class Solution {
public:
void reverseWords(string &s) {
string ans = "", temp;
stringstream sin(s);
while(sin >> temp) {
if(ans != "") {
ans = temp + " " + ans;
} else {
ans = temp;
}
}
s = ans;
}
};