-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1451.cpp
More file actions
29 lines (26 loc) · 665 Bytes
/
Copy path1451.cpp
File metadata and controls
29 lines (26 loc) · 665 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
#pragma GCC optimize("fast")
static auto _ = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
}();
class Solution {
public:
string arrangeWords(string &text) {
map<int, vector<string>> um;
string word, res;
text[0] = tolower(text[0]);
stringstream ss(text);
while (ss >> word)
um[word.size()].push_back(word);
res.reserve(text.size());
for (const auto &[_, v] : um) {
for (const auto &w : v)
res += w + " ";
}
res[0] = toupper(res[0]);
res.pop_back();
return res;
}
};