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

题意:

输入一个字符串长度为5~80,以‘U‘型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等。

trick:

不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是‘ ‘,空格的ascii是32,初读题面时并没有看到要输出空格,因为打印0其实效果看起来好像一样。。。

代码:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
char a[87][87];
int main(){
memset(a,‘ ‘,sizeof(a));
cin>>s;
int n=s.size();
int x=(n+2)/3;
for(int i=1;i<=x;++i)
a[i][1]=s[i-1];
for(int i=x+1;i<=n-x;++i)
a[x][i-x+1]=s[i-1];
for(int i=x;i>=1;--i)
a[i][n-2*x+2]=s[n-i];
for(int i=1;i<=x;++i){
for(int j=1;j<=n-2*x+2;++j)
cout<<a[i][j];
if(i!=x)
cout<<"\n";
}
return 0;
}

原文地址:https://www.cnblogs.com/ldudxy/p/11509301.html

时间: 2024-08-27 13:18:03

【PAT甲级】1031 Hello World for U (20 分)的相关文章

PAT 甲级 1027 Colors in Mars (20 分)

1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the

PAT 甲级 1054 The Dominant Color (20 分)

1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A st

PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)

1058 A+B in Hogwarts (20 分)   If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enou

PAT 甲级 1104 Sum of Number Segments (20分)(有坑,int *int 可能会溢出)

1104 Sum of Number Segments (20分)   Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0

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 example, helloworld can be printed as: h d e l l r lowo That is, the characters must be printed in the original order, starting top-down from the left

1031 Hello World for U (20 分)

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 example, helloworld can be printed as: h d e l l r lowo That is, the characters must be printed in the original order, s

PAT乙级:1053 住房空置率 (20分)

PAT乙级:1053 住房空置率 (20分) 题干 在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断.判断方法如下: 在观察期内,若存在超过一半的日子用电量低于某给定的阈值 e,则该住房为"可能空置": 若观察期超过某给定阈值 D 天,且满足上一个条件,则该住房为"空置". 现给定某居民区的住户用电量数据,请你统计"可能空置"的比率和"空置"比率,即以上两种状态的住房占居民区住房总套数的百分

pat 1124 Raffle for Weibo Followers(20 分)

1124 Raffle for Weibo Followers(20 分) John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give away gifts.

PAT 乙级 1074 宇宙无敌加法器 (20 分)

1074 宇宙无敌加法器 (20 分) 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的.而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为"PAT数".每个 PAT 星人都必须熟记各位数字的进制表,例如"--0527"就表示最低位是 7 进制数.第 2 位是 2 进制数.第 3 位是 5 进制数.第 4 位是 10 进制数,等等.每一位的进制 d 或者是 0(表示十进制).或者是 [2,9] 区间内的整数.理论上这个进制

PAT乙级1023. 组个最小数(20 分)

1023 组个最小数(20 分) 给定数字 0-9 各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位).例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558. 现给定数字,请编写程序输出能够组成的最小的数. 输入格式: 输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0.数字 1.……数字 9 的个数.整数间用一个空格分隔.10 个数字的总个数不超过 50,且至少拥有 1 个非 0 的数字