• 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的话输出会多出一列空格。

  • 相关阅读:
    职业生涯起步不要去顶级公司
    discuz uc密码修改
    习惯决定成功与否
    世上没有理想的工作
    中山市慧海人力资源服务有限公司
    Codeforces Round #365 (Div. 2) B 前缀和
    Codeforces Round #365 (Div. 2) A 水
    tyvj 1067 dp 两次LIS(nlogn)
    Codeforces Round #303 (Div. 2) D 贪心
    Codeforces Round #303 (Div. 2) C dp 贪心
  • 原文地址:https://www.cnblogs.com/fyymonica/p/4168184.html
Copyright © 2020-2023  润新知