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, . "
#include <stdio.h>
#include <string.h>
#define N 110
char a[N][N];
int main()
{
int i, j;
int n = 0;
int max = 0;
int count[N] = {0};
while(gets(a[n]))
{
if(max < strlen(a[n]))
{
max = (int)strlen(a[n]);
}
count[n] = strlen(a[n]);
n++;
}
for(i = 0; i < max; i++)
{
for(j = n-1; j >=0; j--)
{
if(a[j][i] == '\0') //一定要加上这句 不然WA
{
printf("%c", ' ');
}
else
{
printf("%c", a[j][i]);
}
}
printf("\n");
}
return 0;
}
刚开始没加判断的那句一直错。。 加上就AC了 题目不难。。 旋转就是按照二维数组处理 找到各个字符旋转前和旋转后的位置的关系,,找到之后就应该不难解决了