您的答案為: ergoe s leznogyei necoobn iaxeqhss .chmt iaheans gs" e oirlnsotes luetrhn
正確答案為: ergoe s leznogyei necoobn iaxeqhss .chmt iaheans gs" e oirlnsotes luetrhn
程式碼:
#include <iostream>
#include <string>
using namespace std;
int main(void){
string sentence[100]={" "};
short n(0), len(0);
while(getline(cin, sentence[n])){
if(sentence[n].length() > len){ len = sentence[n].length(); }
n++;
}
short i(0), j(0);
for (j=0; j<len; j++){
for (i=n-1; i>=0; i--){
cout<< sentence[i][j];
}
cout<< endl;
}
return 0;
}
-----------------------------------------------------------------------------------
找不出哪裡有錯, 麻煩指點一下, 謝謝
if(j < sentence[i].length()){ cout<< sentence[i][j]; } else{ cout<< " "; }
--------------------------------------------------------------------------------------------
已解決, 在輸出時改為判斷字串長度, 超過則輸出空白.
程式碼如上.