網頁

2014年2月3日 星期一

UVa 490 Rotating Sentences

題意:
  將每一行的句子轉成直的,順序由下到上。
想法:
  將每個句字保存後,依題意順序將句子每個字輸出,如果該列句子已經結束,則輸出空格。


#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;
}

沒有留言:

張貼留言