【PAT甲级】1031 Hello World for U (20 分)
题意:
输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等。
trick:
不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是' ',空格的ascii是32,初读题面时并没有看到要输出空格,因为打印0其实效果看起来好像一样。。。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
char a[][];
int main(){
memset(a,' ',sizeof(a));
cin>>s;
int n=s.size();
int x=(n+)/;
for(int i=;i<=x;++i)
a[i][]=s[i-];
for(int i=x+;i<=n-x;++i)
a[x][i-x+]=s[i-];
for(int i=x;i>=;--i)
a[i][n-*x+]=s[n-i];
for(int i=;i<=x;++i){
for(int j=;j<=n-*x+;++j)
cout<<a[i][j];
if(i!=x)
cout<<"\n";
}
return ;
}
【PAT甲级】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甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- PAT 甲级 1027 Colors in Mars (20 分)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...
- PAT 甲级 1005 Spell It Right (20 分)
1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...
- 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 ha ...
- PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- 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甲级】1054 The Dominant Color (20 分)
题意: 输入两个正整数M和N(M<=800,N<=600),分别代表一张图片的宽度和高度,接着输入N行每行包括M个点的颜色编号,输出这张图片主导色的编号.(一张图片的主导色占据了一半以上的 ...
- 【PAT甲级】1001 A+B Format (20 分)
题意:给两个整数a,b,计算a+b的值并每三位用逗号隔开输出(−1e6≤a,b≤1e6) AAAAAccepted code: #include<bits/stdc++.h> us ...
随机推荐
- 安装Redis教程
今天因为要用到redis中间件,于是自己就尝试安装一下,我把步骤记录了,分享给大家,希望能对大家有帮助! 我的博客地址: https://www.cnblogs.com/themysteryofhac ...
- Codeforces Gym 102392F Game on a Tree (SEERC2019 F题) 题解
题目链接:https://codeforces.com/gym/102392/problem/F 题意:被这题题意坑了很久,大意是说有一棵根为 \(1\) 的树,每个节点初始都是白色, \(Alice ...
- 基于bs4库的HTML内容查找方法
一.信息提取实例 提取HTML中所有的URL链接 思路:1)搜索到所有的<a>标签 2)解析<a>标签格式,提取href后的链接内容 >>> import r ...
- Unity生成的WebGL如何在浏览器中运行
前言:以为在学完了COMP30019后,应该不会再接触Unity了,没想到之后实习让我去做把一个Unity项目转到WebGL,而关于Unity的WebGL资料很少,基本除了Unity的Manual就只 ...
- cmake 单个目录多个文件的情况
参考:https://www.hahack.com/codes/cmake/# 源文件一共有三个:main.cpp.MathFunctions.h.MathFunctions.cpp 文件内容分别如下 ...
- 排序算法之选择排序的python实现
选择排序算法的工作原理如下: 1. 首先在序列中找到最小或最大元素,存放到排序序列的前或后. 2. 然后,再从剩余元素中继续寻找最小或最大元素. 3. 然后放到已排序序列的末尾. 4. 以此类推,直到 ...
- html 中js 如何给字符串加换行符
var str = 你好'+"\n"+ '世界'; 这种写法在html中是会被识别为"你好\n世界" 那么如何保证其这么写会被识别,只需要在该div的样式中加入 ...
- Spring学习(十)
需要的jar包 1.Spring核心必须依赖的库:commons-logging-1.1.1.jar2.Spring IoC部分核心库: spring-beans-4.3.9.RELEASE.jar ...
- 获取天气预报java代码
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; imp ...
- java中关于类和对象的一些思考
就这个问题而言 第一种和第二种定义的变量并不是一种形式 前者我们称为原始数据变量 后者我们称为对象变量 这两种变量的创建方式,定义方式,使用方式都有着很多不同 需要引起注意. 在java中,有着基本的 ...