1
class Solution {
2
public:
3
string sortSentence(string s) {
4
stringstream words(s);
5
string word;
6
pair<int, string> m;
7
vector<pair<int, string>> sent;
8

9
// SECTION 1
10
while (words >> word) {
11
int len = word.size();
12
int i = int(word[len - 1]) - 48;
13
sent.push_back(make_pair(i, word.substr(0, len - 1)));
14
}
15

16
// SECTION 2
17
sort(sent.begin(), sent.end());
18

19
// SECTION 3
20
string ans = "";
21
int len = sent.size();
22
for (int i = 0; i < len; i++) {
23
ans += sent[i].second;
24
if (i != len - 1) ans += " ";
25
}
26

27
return ans;
28
}
29
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0