【題目敘述】https://zerojudge.tw/ShowProblem?problemid=c045
【解題想法】行列互換
#include <iostream>
using namespace std;
string s[105];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int col = 0, row = 0;
while (getline(cin, s[col])){
row = max(row, (int)s[col].size());
col++;
}
for (int i = 0; i < row; i++){
for (int j = col-1; j >= 0; j--){
if (i >= s[j].size()) cout << " ";
else cout << s[j][i];
}
cout << "\n";
}
return 0;
}
Python code (credit: Amy Chou)
s = []
while True:
try:
s.append(input())
except:
break
col = len(s)
row = 0
for i in range(col):
row = max(row, len(s[i]))
for i in range(row):
for j in range(col-1, -1, -1):
if i >= len(s[j]):
print(" ", end="")
else:
print(s[j][i], end="")
print()