將每一行的句子轉成直的,順序由下到上。
想法:
將每個句字保存後,依題意順序將句子每個字輸出,如果該列句子已經結束,則輸出空格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
using namespace std; | |
int main() | |
{ | |
// freopen ("input.txt","rt",stdin); | |
char sentence[101][101]; | |
int N=0,length[101]; | |
int Max_length=0; | |
while (gets(sentence[N])) { | |
length[N] = strlen(sentence[N]); | |
if (length[N] > Max_length) Max_length = length[N]; | |
N++; | |
} | |
for (int i=0; i<Max_length; i++){ | |
for (int j=N-1; j>=0; j--){ | |
if (i < length[j]) | |
printf("%c",sentence[j][i]); | |
else | |
printf(" "); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言