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 }
  • 相关阅读:
    你是一直认为 count(1) 比 count(*) 效率高么?
    php 判断是不是https链接
    php 版本比较
    php 执行效率
    redis 队列缓存 + mysql 批量入库 + php 离线整合
    php 高并发下数据同步的问题
    一个合格的工程师的知识结构
    php 代码编写的格式
    php 四种基础算法 ---- 快速排序法
    php 四种基础算法 ---- 插入排序法
  • 原文地址:https://www.cnblogs.com/SDUTYST/p/2512186.html
Copyright © 2011-2022 走看看