Click
Here to go back to the homepage.
Sideways Sorting Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int nWords, chars;
cin >> nWords >> chars;
while(nWords > 0){
string words[chars];
for(int i = 0; i < nWords; i++){
for(int j = 0; j < chars; j++){
char c;
cin >> c;
words[j].push_back(c);
}
}
sort(words, words + chars, [](string a, string b){
transform(a.begin(), a.end(), a.begin(), [](unsigned char c){
return tolower(c);
});
transform(b.begin(), b.end(), b.begin(), [](unsigned char c){
return tolower(c);
});
return a < b;
});
for(int i = 0; i < nWords; i++){
for(int j = 0; j < chars; j++){
cout << words[j][i];
}
cout << endl;
}
cout << endl;
cin >> nWords >> chars;
}
return 0;
}