zoukankan      html  css  js  c++  java
  • 1031. Hello World for U (20)

    题目链接:http://www.patest.cn/contests/pat-a-practise/1031

    题目:


    分析:

    排版题。注意先计算好最后一排的字符数,然后计算前面几排的空格数。难度不大

    这里有个小技巧,就是先把要输出的结果都存储到ouput[ ]字符数组中。等所有拍好后再输出output[ ]就可以。这样能够方便得写处于右边的一列的循环。


    AC代码:

    #include<stdio.h>
    #include<string>
    using namespace std;
    char output[30][30];//用于存储结果最后输出
    char str[81];
    int main(void){
     //freopen("F://Temp/input.txt","r",stdin);
     gets(str);
     string str1 = string(str);
     int size = str1.size();
     int h = (size + 2) / 3;
     int w = size - 2 * h;
     int point = 0;
     for(int i= 0;i <h;i ++){
      for(int j= 0;j <w+ 2;j ++){
       output[i][j] = ' ';
      }
     }
     for(int i = 0;i < h;i ++,point ++){
      output[i][0] = str[point];
     }//最左边的一列
     for(int i= 1;i <= w;i ++,point ++){
      output[h - 1][i] = str[point];
     }//最以下一行
     for(int i= h - 1; i >= 0;i --,point ++){
      output[i][w + 1] = str[point];
     }//最右边一列
     for(int i= 0;i < h;i ++){
      for(int j= 0 ;j <w+ 2;j ++){
       printf("%c",output[i][j]);
      }
      printf("
    ");
     }
     return 0;
    }


    截图:


    ——Apie陈小旭

  • 相关阅读:
    [NoiPlus2016]天天爱跑步
    POJ3539 Elevator
    CodeForces 37E Trial for Chief
    CodeForces 986C AND Graph
    [tyvj-2054][Nescafé29]四叶草魔杖 费用流
    [CodeForces]986A Fair
    [CodeForces]981C Useful Decomposition
    分配问题
    圆桌问题
    数字梯形问题
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5308612.html
Copyright © 2011-2022 走看看