题目链接: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. poj 1273.PIG (最大流)

    网络流 关键是建图,思路在代码里 /* 最大流SAP 邻接表 思路:基本源于FF方法,给每个顶点设定层次标号,和允许弧. 优化: 1.当前弧优化(重要). 1.每找到以条增广路回退到断点(常数优化). ...

  2. hold

    嘿嘿,很久没写博客了.一懒一拖一浮躁就不行了. 果然烦心事太多,一直懒得编程.结果还是编程才能平复我啊! 明天那什么,别担心,平常心嘛! 还好,看了几部电影,不算没收获.自己有意思就看看电影,别瞎想啥 ...

  3. 解决nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误

    重新启动服务器,访问web服务发现无法浏览,登陆服务器之 后进到nginx使用./nginx -s reload重新读取配置文件,发现报nginx: [error] open() "/usr ...

  4. 那些年被我坑过的Python——一夫当关 第十三章(堡垒机初步设计)

      堡垒机架构 堡垒机的主要作用权限控制和用户行为审计,堡垒机就像一个城堡的大门,城堡里的所有建筑就是你不同的业务系统 , 每个想进入城堡的人都必须经过城堡大门并经过大门守卫的授权,每个进入城堡的人必 ...

  5. iOS中获取各种文件的目录路径和文件

    iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory ...

  6. 大神眼中的React Native--备用

    当我第一次尝试ReactNative的时候,我觉得这只是网页开发者涉足原生移动应用领域的歪门邪道. 我认为一个js开发者可以使用javascript来构建iPhone应用确实是一件很酷的事情,但是我很 ...

  7. ASP.NET 安全认证

    一. 新建一个测试项目 新建一个测试项目,包含三张页面(Default.aspx.Login.aspx.UserInfo.aspx).   二. 修改 Web.config 1.把<authen ...

  8. 转:理解 PHP 中的 Streams

    本文转自:开源中国社区 [http://www.oschina.net]本文标题:理解 PHP 中的 Streams 本文地址:http://www.oschina.net/translate/und ...

  9. unity3d中的http通信

    转载 http://blog.csdn.net/mfc11/article/details/8188785的博客,如果侵权,请留言我及时删除! 前言 Unity3d 是一个跨平台的引擎,在移动互联网浪 ...

  10. Color the Fence

    Codeforces Round #202 (Div. 2) B:http://codeforces.com/problemset/problem/349/B 题意:给你一些颜料,然后你可以用这些颜料 ...