该死的题,很久都AC不了
Rotating Sentences
Rotating Sentences |
In ``Rotating Sentences,'' you are asked to rotate a series of input sentences 90 degrees clockwise. So instead of displaying the input sentences from left to right and top to bottom, your program will display them from top to bottom and right to left.
Input and Output
As input to your program, you will be given a maximum of 100 sentences, each not exceeding 100 characters long. Legal characters include: newline, space, any punctuation characters, digits, and lower case or upper case English letters. (NOTE: Tabs are not legal characters.)
The output of the program should have the last sentence printed out vertically in the leftmost column; the first sentence of the input would subsequently end up at the rightmost column.
Sample Input
Rene Decartes once said, "I think, therefore I am."
Sample Output
"R Ie n te h iD ne kc ,a r tt he es r eo fn oc re e s Ia i ad m, . "
明明输出是对的,但就是一直WA。。。无语了,深感自己边界处理能力不行,参照了一下青竹淡雅同学的代码,发现把多余的字符都转为空格也不失为一种好办法,就不用麻烦的考虑边界了。
#include<stdio.h>
#include<string.h>
char str[110][110];
int main()
{
int i,j,n,k;
memset(str,0,sizeof(str));
int size=0,max=0;
while(gets(str[size])){
n=strlen(str[size]);
if(n>max)
max=n;
size++;
}
for(i=0;i<size;i++)
for(j=0;j<max;j++)
if(!str[i][j])
str[i][j]=' ';
for(j=0;j<max;j++)
{
for(i=size-1;i>=0;i--)
printf("%c",str[i][j]);
printf("\n");
}
return 0;
}