首页 > 其他 > 详细

490 - Rotating Sentences

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

 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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!