UVa 490 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, . "
1 #include <stdio.h> 2 #include <string.h> 3 int main(int argc, const char *argv[]) 4 { 5 int a[101][101], i = 1, j = 1, c, k, m, row = 0, colum; 6 memset(a, 0, sizeof(a)); 7 while ((c = getchar()) != EOF) { 8 if (c != '\n') 9 a[i][j++] = c; 10 else { 11 if(j > row) 12 row = j; 13 j = 1; 14 i++; 15 } 16 } 17 colum = i - 1; 18 for (k = 1; k < row; k++) { 19 for (m = colum; m > 0; m--) { 20 if(a[m][k] != 0) 21 putchar(a[m][k]); 22 else 23 putchar(' '); 24 } 25 printf("\n"); 26 } 27 return 0; 28 }