题目链接: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("\n");
}
return 0;
}

截图:

——Apie陈小旭

1031. Hello World for U (20)的更多相关文章

  1. PAT 甲级 1031 Hello World for U (20 分)(一开始没看懂题意)

    1031 Hello World for U (20 分)   Given any string of N (≥) characters, you are asked to form the char ...

  2. PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...

  3. 1031. Hello World for U (20) PAT

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...

  4. PAT甲题题解-1031. Hello World for U (20)-字符串处理,水

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  5. PAT (Advanced Level) 1031. Hello World for U (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  6. PAT Advanced 1031 Hello World for U (20 分)

    Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For ...

  7. 【PAT甲级】1031 Hello World for U (20 分)

    题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是 ...

  8. 1031 Hello World for U (20分)

    Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For ...

  9. 浙大pat 1031题解

    1031. Hello World for U (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...

随机推荐

  1. print 函数的进一步理解

    没有括号的时候,pritn是列表操作符,会把其后列表里所有东西都数出来. 但是假如print后面紧跟着左括号,它就是一个函数调用,只会将括号内的东西输出来. “假如它看起来像函数调用,它就是一个函数调 ...

  2. asp.net MVC 从其它项目复制过来的Area里面的Controllers文件读取不到

    从其实项目复制过来的Controllers,在访问时显示不存在文件 检查一下对应的area里面的AreaRegistration文件的命名空间是否一致

  3. masonry结合json 制作无限滚动的瀑布流

    做前端这行的 能直接贴代码就直接贴代码了,不用多说什么别的 效果需要引入jquery和jquery.masonry.min.js这两个JS JS代码如下: $(document).ready(func ...

  4. Python自动化运维之24、JQuery

    jQuery是一个兼容多浏览器的javascript库,核心理念是write less,do more(写得更少,做得更多).它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, ...

  5. __block存储类型

    __block存储类型 你可以指定引入一个变量为可更改的,即读-写的,通过应用__block 存储类型修饰符.局部变量的__block 的存储和 register.auto.static 等存储类型相 ...

  6. SQL联合索引 与 单一列的索引

    SQL联合索引 与 单一列的索引 标签: sqlwebobjectstatistics优化磁盘 2012-06-12 13:46 27992人阅读 评论(1) 收藏 举报  分类: 数据库(94)  ...

  7. BZOJ 1029 建筑抢修

    Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修 ...

  8. java Active Object模式(上)

    Active Object模式简介 Active Object模式是一种异步编程模式.它通过对方法的调用与方法的执行进行解耦来提高并发性.若以任务的概念来说,Active Object模式的核心则是它 ...

  9. cf B Three matrices

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ][] ...

  10. JFS 文件系统概述及布局分析

    JFS 文件系统概述及布局分析 日志文件系统如何缩短系统重启时间 如果发生系统崩溃,JFS 提供了快速文件系统重启.通过使用数据库日志技术,JFS 能在几秒或几分钟之内把文件系统恢复到一致状态,而非日 ...