码迷,mamicode.com
首页 > 其他好文 > 详细

490 - Rotating Sentences

时间:2014-12-16 22:23:20      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   io   color   os   sp   for   strong   


 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,
.
"
----------------------------------------------------------------------------------------
ac代码:
 1 #include<stdio.h>
 2 #define MAXN 100+10
 3 char array[MAXN][MAXN];
 4 int rowArray[MAXN] = {0};
 5 int maxCol = 0;
 6 int main(){
 7 
 8     char c;
 9     int row = 0,column = 0;
10 
11     int i,j;
12 
13     while((c = getchar())!= EOF){
14         if(c == \n){//遇到换行,行数加1,列数清0
15             row++;
16             column = 0;
17         }else{
18             array[row][column++] = c;
19             ++rowArray[row];
20             if(rowArray[row] > maxCol){
21                 maxCol = rowArray[row];
22             }
23         }
24     }
25     
26     for(i = 0; i < maxCol; i++){
27         for(j = row-1; j >= 0; j--){
28             c = (i < rowArray[j]) ? array[j][i]: ;
29             printf("%c",c);
30         }
31         printf("\n");
32     }
33 
34    return 0; 
35 }

其中需要注意的是:

27行,j = row -1,若是j=row的话输出会多出一列空格。

 

490 - Rotating Sentences

标签:style   blog   ar   io   color   os   sp   for   strong   

原文地址:http://www.cnblogs.com/fyymonica/p/4168184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!