Skip to content

Instantly share code, notes, and snippets.

@NicolasFrancaX
Created January 8, 2019 21:27
Show Gist options
  • Save NicolasFrancaX/e2b9cb3055eae78517466d4e0e112d96 to your computer and use it in GitHub Desktop.
Save NicolasFrancaX/e2b9cb3055eae78517466d4e0e112d96 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
#include <map>
#include <vector>
using namespace std;
int main() {
string text;
string word;
unsigned int g;
int N;
int p;
cin >> N;
cin.ignore(100, '\n');
while (N--) {
g = 0;
p = 0;
map<int, vector<string>> m;
getline(cin, text);
stringstream ss(text);
while (ss >> word) {
if (g < word.length()) {
g = word.length();
}
m[word.length()].push_back(word);
}
for (int i = g; i > 0; i--) {
for (vector<string>::iterator it = m[i].begin(); it != m[i].end(); it++) {
if (p++ == 0) {
cout << *it;
} else {
cout << " " << *it;
}
}
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment