[UVA][Normal] 490 - Rotating Sentences
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, . "
殺死人不償命的空白處理, 要補滿 n*m 的方格
#include <stdio.h>
#include <string.h>
int main() {
char s[105][105], c[105][105];
int n = 0, m = 0, i, j;
while(gets(s[n]))
n++;
memset(c, ' ', sizeof(c));
for(i = 0; i < n; i++) {
for(j = 0; s[i][j]; j++)
c[j][n-i-1] = s[i][j];
m = m > j ? m : j;
}
for(i = 0; i < m; i++) {
c[i][n] = '\0';
puts(c[i]);
}
return 0;
}