# (YKL42(UVA490)) Rotating Sentences : YKL42_UVA490_Rotating_Sentences.cpp ```cpp!= #include <iostream> #include <vector> using namespace std; int main(){ vector<string> sentences; // 用於存儲每一行輸入的向量 string sentence; // 用於存儲當前讀取的行 int max_length = 0; // 用於記錄最長行的長度 // 讀取所有輸入行 while(getline(cin, sentence)){ sentences.push_back(sentence); // 將當前行加入向量 max_length = max(max_length, (int)sentence.length()); // 更新最長行的長度 // 節省記憶體 } // 旋轉並輸出 for(int i = 0; i < max_length; i++){ // 遍歷每一列 for(int j = sentences.size() - 1; j >= 0; j--){ // 從最後一行開始遍歷每一行 if(i < sentences[j].length()){ // 如果當前列在當前行的範圍內 cout << sentences[j][i]; // 輸出當前列的字符 }else{ cout << " "; // 如果當前列超出當前行的範圍,輸出空格 } } cout << endl; // 每列輸出完後換行 } } ```  
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up