• 490



     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 == '
    '){//遇到换行,行数加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("
    ");
    32     }
    33 
    34    return 0; 
    35 }

    其中需要注意的是:

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

  • 相关阅读:
    vCenter6.7的简单安装与使用
    大家来找茬
    Android APP分享功能实现
    为免费app嵌入Admob广告
    Google Admob广告Android全攻略1
    开始Admob广告盈利模式详细教程
    android软件中加入广告实现方法
    onWindowFocusChanged重要作用 and Activity生命周期
    WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式
    android之intent显式,显式学习
  • 原文地址:https://www.cnblogs.com/fyymonica/p/4168184.html
Copyright © 2020-2023  润新知