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("\n");
}
return 0;
}
截图:
——Apie陈小旭
1031. Hello World for U (20)的更多相关文章
- 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 ...
- 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) ...
- 1031. Hello World for U (20) PAT
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...
- PAT甲题题解-1031. Hello World for U (20)-字符串处理,水
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- PAT (Advanced Level) 1031. Hello World for U (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 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 ...
- 【PAT甲级】1031 Hello World for U (20 分)
题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是 ...
- 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 ...
- 浙大pat 1031题解
1031. Hello World for U (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...
随机推荐
- PHPCMS 使用图示和PHPCMS二次开发教程(转)
PHPCMS V9 核心文件说明 模块与控制器 模块: phpcms v9框架中的模块,位于phpcms/modules目录中 每一个目录称之为一个模块.即url访问中的m. 访问content模块示 ...
- lsmod
http://blog.csdn.net/yuan892173701/article/details/8960607 抽空写下
- 项目管理模式——Projects
Github 新的项目管理模式——Projects Github 新的项目管理模式——Projects Issues Github 中传统的项目管理是使用 issue 和 pull request 进 ...
- 应用hexo(rss插件)
使用RSS插件,来生成rss信息. 装载RSS插件 hexo根目录下进入git命令台 npm install hexo-generator-sitemap 启用RSS插件 hexo根目录下的 _con ...
- unity3d中脚本生命周期(MonoBehaviour lifecycle)
最近在做一个小示例,发现类继承于MonoBehaviour的类,有很多个方法,于是乎必然要问出一个问题:这么多个方法,执行先后顺序是如何的呢?内部是如何进行管理的呢?于是在网上找了许多资料,发现了Ri ...
- [BZOJ 1874] [BeiJing2009 WinterCamp] 取石子游戏 【博弈论 | SG函数】
题目链接:BZOJ - 1874 题目分析 这个是一种组合游戏,是许多单个SG游戏的和. 就是指,总的游戏由许多单个SG游戏组合而成,每个SG游戏(也就是每一堆石子)之间互不干扰,每次从所有的单个游戏 ...
- Oracle开始从Java运行时中移除JAR包
早在2012年8月,在Java平台首席架构师Mark Reinhold宣布模块化项目Jigsaw之后不久,JEP 162这一题为“准备模块化”的提案就指出,在Jigsaw项目中为模块化系统开发的代码不 ...
- Automated Telephone Exchange
Time Limit: 3000MS Memory limit: 65536K 题目描述In St Petersburg phone numbers are formatted as “XXX–XX– ...
- keil uVision4一些使用总结(汉字注释,C关键字等)
近日心血来潮,下载了最新的版的keil,再加上protues ,想弄个虚拟环境.主要原因还是经济问题.电子元件,是要花钱的... 今天遇到些keil uVision 4使用方面的问题,记录下来,方便以 ...
- 【转】Android Recovery模式
原文网址:http://leox.iteye.com/blog/975303 (muddogxp 原创,转载请注明) Recovery简介 Android利用Recovery模式,进行恢复出厂设置,O ...