题目链接: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. gdb小结

    testGdb.c #include<stdio.h> int getSum(int a,int b){ printf("a+b=%d\n",a+b); return ...

  2. 五分钟看懂js关键字this

    this是js里面很常用的关键字,而灵活的js也赋予了这个关键字无穷的生命力,相信你也有被它糊弄的时候,我总结了一个6字原则,大部分场合都能清醒分辨this到底指向who,跟大家分享一下,欢迎指正. ...

  3. 关于win8.1“连接被远程计算机关闭”的一种解决方案

    我就是连接的时候出现"连接被远程计算机关闭",然后想着可能是win8更新之后网络协议 出问题了,后来无意中发现e信在第一次启动的时候会在网络适配器中会多出很多网卡,其中三个是带感叹 ...

  4. 3、MyBatis.Net学习笔记之增删改

    增删改之前先说一下笔记1里提到的一个无法创建ISqlMapper对象的问题. <resultMaps> <resultMap id="FullResultMap" ...

  5. hdu 5128 The E-pang Palace

    http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意:给定N个点,选出其中8个点组成两个矩形,使得两个矩形的面积和最大. 思路:找出所有的矩形,然后枚举, ...

  6. win平台下, 检测网络是否连接最好的办法

    [Delphi]检查URL是否有效的函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 function CheckUr ...

  7. delphi XML 原来可以玩接口

    以下代码旨在 脱离TXMLDocument 操作 xml unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Class ...

  8. PHP打印各种金字塔!

    PHP打印各种金字塔! <?php for($i=1;$i<=7;$i++){ for($j=1;$j<=5-$i;$j++){ echo ''; } for($k=1;$k< ...

  9. sphinx插入css

    使用role指令达到目的. We can put following lines at the beginning of our RST file to specify its style. .. r ...

  10. bzoj1146

    这是一道无比繁琐的题目话说这道题使我第一次练dfs序,比较感动:首先dfs序就是在dfs过程中按照访问的顺序给每个点标上两个“时间戳”一个是第一次访问到点i时的时间戳c[i],一个是访问完以i为根时的 ...