-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee1244.cpp
More file actions
45 lines (35 loc) · 904 Bytes
/
Copy pathbee1244.cpp
File metadata and controls
45 lines (35 loc) · 904 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Contest : Beecrowd
* Problem : 1244 - Ordenação por Tamanho
* Link : https://judge.beecrowd.com/pt/problems/view/1244
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
bool cmp(string a, string b) {
return a.length() > b.length();
}
int main() {
fastio
// fastio
int tc; cin >> tc;
cin.ignore();
while (tc--) {
string frase, palavra;
vector<string> palavras;
getline(cin, frase);
for (int i = 0; i < frase.size(); ++i) {
if (frase[i] != ' ') palavra += frase[i];
else {
palavras.push_back(palavra);
palavra.clear();
}
}
palavras.push_back(palavra);
stable_sort(palavras.begin(), palavras.end(), cmp);
for (int i = 0; i < palavras.size() - 1; ++i) cout << palavras[i] << " ";
cout << palavras.back() << endl;
}
return 0;
}