1031. Hello World for U (20)
2016-03-22 21:36
288 查看
题目链接:http://www.patest.cn/contests/pat-a-practise/1031
题目:
分析:
排版题。注意先计算好最后一排的字符数,然后计算前面几排的空格数。难度不大
这里有个小技巧,就是先把要输出的结果都存储到ouput[ ]字符数组中。等所有拍好后再输出output[ ]就可以。这样能够方便得写处于右边的一列的循环。
AC代码:
截图:
——Apie陈小旭
题目:
分析:
排版题。注意先计算好最后一排的字符数,然后计算前面几排的空格数。难度不大
这里有个小技巧,就是先把要输出的结果都存储到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("\n"); } return 0; }
截图:
——Apie陈小旭
相关文章推荐
- 扩展欧几里得算法
- JVM之类文件结构
- 史上最牛逼程序猿-《棋魂》
- 商业即生活,一些思考和感悟
- 商业即生活,一些思考和感悟
- CentOS统计文件并显示图片文件
- 小食代遇到的坑
- Android RecyclerView 使用完全解析 体验艺术般的控件
- (嵌入式开发)自己写bootloader之编写第二阶段
- 商业即生活,一些思考和感悟
- 关于oracle数据库(8)查询2
- BZOJ 3223 文艺平衡树
- JSONObject 解析json的步骤
- Ubuntu14.04下“E: 无法找到软件包”的解决
- vagrant使用
- Python学习笔记(一)
- Android原理探究:Activity任务栈Task的简单探讨
- 64位的ubuntu14.04 LTS安装 Linux交叉编译工具链及32位“ia32-libs”依赖库
- 一人一狗,那一年
- html页面内容超出后显示水平滚动条的问题