題目
解法
top to bottom, right to left
重要提醒:如果該字串長度不足,要輸出空白字元。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
string s;
vector<string> v;
int maxLength = 0;
while(getline(cin, s)){
v.push_back(s);
maxLength = max(maxLength, (int)s.length());
}
for(int i=0; i<maxLength; i++){
for(int j=v.size()-1; j>=0; j--){
if(v[j].length() - 1 >= i){
cout << v[j][i];
}else{
cout << ' ';
}
}
cout << '\n';
}
}👉 回到:【CPE大學程式能力檢定】目錄