zoukankan      html  css  js  c++  java
  • uva 490 Rotating Sentences

    这道题目在题目的示例输入与输出上面可能会误导我们,如果像我这样英语不是很好,又懒得啃题目意思的人来说,很容易就由于猜测题目意思做题,而导致一次次的出现错误,不是PE就是wrong answer

    具体的细节会在代码中讲解

    View Code
     1  Rotating Sentences 
     2 
     3 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.
     4 
     5 Input and Output
     6 
     7 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.)
     8 
     9 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.
    10 
    11 Sample Input
    12 
    13 Rene Decartes once said,
    14 "I think, therefore I am."
    15 
    16 Sample Output
    17 
    18 "R
    19 Ie
    20  n
    21 te
    22 h 
    23 iD
    24 ne
    25 kc
    26 ,a
    27  r
    28 tt
    29 he
    30 es
    31 r
    32 eo
    33 fn
    34 oc
    35 re
    36 e
    37  s
    38 Ia
    39  i
    40 ad
    41 m,
    42 .
    43 "
    44 具体的代码实现如下:
    45 其实细节不是很多,只要注意空格的输出就行了
    46 #include<stdio.h>
    47 #include<string.h>
    48 int main()
    49 {
    50     char st[102][102],ch;
    51     int maxlen = 0,top = 0,lenth[102];
    52     while((gets(st[top])) != NULL)
    53     {
    54         if(strlen(st[top]) > maxlen)
    55             maxlen = strlen(st[top]);
    56         lenth[top] = strlen(st[top]);
    57         top++;
    58     }
    59     int i,j,k;
    60     for(i = 0;i < maxlen; i++)
    61     {
    62         for(j = top-1;j >= 0; --j)
    63         {
    64             if(lenth[j] > i)
    65                 printf("%c",st[j][i]);
    66             else//其实所谓的细节就是在某一行的没有字符的位置,输出空格
    67                 printf(" ");
    68         }
    69         printf("\n");
    70     }
    71     return 0;
    72 }
  • 相关阅读:
    Thinkphp无法加载验证码 undefined function Thinkimagettftext() 解决方案 mac系统
    fragment使用不当 导致java.lang.IllegalStateException
    怎样从GitHub项目中,下载单个文件夹或文件
    Android 5.0 app样式
    OpenCV fitline直线拟合函数学习
    Linux文件系统
    Ubuntu 12.04 笔记本触摸板失灵解决方法
    利用微软测试工具PICT生成测试用例
    Myeclipse 使用JUnit 进行单元测试
    Myeclipse 2014 安装checkstyle、PMD和Metrics
  • 原文地址:https://www.cnblogs.com/SDUTYST/p/2512186.html
Copyright © 2011-2022 走看看