【題解】CPE 一顆星選集:12. Rotating Sentences

題目

UVa 連結
ZeroJudge 連結

解法

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大學程式能力檢定】目錄
發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *