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 ...
随机推荐
- TabControl控件中TabPage的显示和隐藏
TabPage里面含有方法Hide和Show,但没有任何作用,实际隐藏和显示需要使用如下2个方法 方法一:此方法比较简单 TabPageServo.Parent = Nothing //隐藏 Ta ...
- 反射给对象赋值遇到的问题——类型转换[转http://blog.csdn.net/xiaohan2826/article/details/8536074]
发布时间:2012-10-25 10:49浏览次数:225 给一个对象属性赋值可以通过PropertyInfo.SetValue()方式进行赋值,但要注意值的类型要与属性保持一致. 创建对象实例的 ...
- 编译内核出错:invalid option `abi=aapcs-linux' 解决办法
出现此问题的原因是由于kernel feature中选中了Use the ARM EABIto compile the kernel引起的,有两各解决办法: 1)换编译器为arm-linux-gcc ...
- X86架构与ARM架构比较
引言 CPU是怎样运作的? CPU的运作与人脑的运作差不多.先谈一下人这个系统的工作方式.眼镜.耳朵.舌头.皮肤等等感觉器官接收到“触觉”,把信息传给大脑,大脑把信息处理后,把处理结果送给手.脚.嘴等 ...
- hdu3652B-number
Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal for ...
- Java中的那些名词术语(不断更新中)
在工作和学习中,总会遇到各种术语.岁月不饶人,记忆力越来越下降.在这里记录下那些曾经关注过学习过的东西. POJO: Plain Old Java Object DI: Dependency Inje ...
- linux系统下root用户和普通用户的时区不一致
1. 发现这个问题是在root下执行 date -R 和 普通用户下执行 date -R,发现时区不一致 2. 在一些linux机器下,发现是一致的 3. 什么原因呢?找了半天,最后发现 时区一致的机 ...
- ios入门之c语言篇——基本函数——3——判断日期是一年的第几天
3.判断日期是一年的第几天 参数返回值解析: 参数: y:int,年份: m:int,月份 d:int,日期 返回值: sum:传入日期是当年的第几天: 函数解析: leapyear(y);判断y是不 ...
- ASP.NET Routing
ASP.NET Routing Other Versions ASP.NET routing enables you to use URLs that do not have to map to ...
- Gvim一些基本配置
介绍一些关于Gvim(windows 7 32位 Vim 7.4)的基本配置,除了特别说明,代码一律添加在安装目录下的_vimrc文件中. 1.取消自动备份,这行代码需要添加在 _vimrc文件中的b ...