zoukankan      html  css  js  c++  java
  • 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,
    .
    "
    ----------------------------------------------------------------------------------------------------------------------------
     1 #include <cstdio>
     2 #include <cstring>
     3 
     4 const int maxn=100+10;
     5 char data[maxn][maxn];
     6 int length[maxn],max_length=0;
     7 int main(){
     8     int line;
     9     for(line=0;fgets(data[line],maxn,stdin)!=NULL;line++){//fgets()会读入换行符,后添加'
    ';
    10         length[line]=strlen(data[line])-1;               //而gets()不读入换行符,直接添加'
    '
    11         if(length[line]>max_length)
    12             max_length=length[line];
    13     }
    14 
    15     for(int i=0;i<max_length;i++){
    16         for(int j=line-1;j>=0;j--)
    17                 printf("%c",(i<length[j]?data[j][i]:' '));
    18         printf("
    ");
    19     }
    20     return 0;
    21 }
  • 相关阅读:
    hadoop3.0.0测验
    红外遥控器通信原理_红外遥控器协议
    N76E003之WDT(看门狗定时器)
    N76E003之IIC
    电阻之上拉电阻与下拉电阻详解(转)
    GPIO输入输出各种模式(推挽、开漏、准双向端口)详解(转)
    N76E003之IO控制
    N76E003之SPI
    51单片机的idata,xdata,pdata,data的详解(转)
    N76E003之ISP
  • 原文地址:https://www.cnblogs.com/purgiant/p/3199757.html
Copyright © 2011-2022 走看看