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 vertical line with n​1​​ characters, then left to right along the bottom line with n​2​​ characters, and finally bottom-up along the vertical line with n​3​​ characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n​1​​=n​3​​=max { k | k≤n​2​​ for all 3 } with n​1​​+n​2​​+n​3​​−2=N.

Input Specification:

Each input file contains one test case. Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.

Output Specification:

For each test case, print the input string in the shape of U as specified in the description.

Sample Input:

helloworld!

Sample Output:

h   !
e d
l l
lowor
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 char ans[][]; int main(){
memset(ans,' ', sizeof(ans));
string s;
cin >> s;
int N = s.size();
int n1,n2,n3;
n1 = n3 = (N+)/;
n2 = (N+)% + n1;
for(int i=;i < n1;i++){
ans[i][] = s[i];
}
for(int i=;i < n2;i++){
ans[n1-][i] = s[n1-+i];
}
for(int i=n3-;i >= ;i--){
ans[i][n2-] = s[n1+n2-+(n3--i)];
} for(int i=;i < n1;i++){
for(int j=;j < n2;j++){
cout << ans[i][j];
}
if(i != n1)cout << endl;
} return ;
}

当提交出现全错的情况说明输出格式错了,比如这题,没有memset char数组是不对的,以后所有数组记得要初始化。

 

PAT 1031 Hello World for U的更多相关文章

  1. 浙大pat 1031题解

    1031. Hello World for U (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...

  2. PAT 1031 查验身份证(15)(C++&Python)

    1031 查验身份证(15)(15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8, ...

  3. PAT 1031 Hello World for U[一般]

    1031 Hello World for U (20 分) Given any string of N (≥5) characters, you are asked to form the chara ...

  4. PAT——1031. 查验身份证

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  5. PAT 1031. 查验身份证(15)

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  6. PAT 1031 查验身份证

    https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 一个合法的身份证号码由17位地区.日期编号和 ...

  7. 1031. Hello World for U (20) PAT

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...

  8. PAT (Basic Level) Practise (中文)-1031. 查验身份证(15)

    PAT (Basic Level) Practise (中文)-1031. 查验身份证(15) http://www.patest.cn/contests/pat-b-practise/1031 一个 ...

  9. PAT乙级1031

    题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 题解 emmm.对于每个身份证号, ...

随机推荐

  1. [关于前端数据] - serialize()的使用

    虽然是拼接字符串,但是也能通过post方式提交 $("#signUpForm").serialize() 结果 controller照样使用实例接收数据即可

  2. Kubernetes之Controllers一

    ReplicaSet is the next-generation Replication Controller. The only difference between a ReplicaSet a ...

  3. eclipse创建maven web项目工程步骤示例

    参考链接:https://www.cnblogs.com/noteless/p/5213075.html 需求表均同springmvc案例 此处只是使用maven 注意,以下所有需要建立在你的ecli ...

  4. hihoCoder 1116 计算(线段树)

    http://hihocoder.com/problemset/problem/1116 题意: 思路: 用线段树解决,每个节点需要设置4个变量,sum记录答案,all记录整个区间的乘积,pre记录该 ...

  5. PHP 常见的数据加密技术

    单项散列加密技术(不可逆的加密) 把任意长的输入字符串变化为固定长的输出串的一种函数 MD5 string md5 ( string $str [, bool $raw_output = false ...

  6. OpenLayers中的球面墨卡托投影

    最近看OpenLayers,研究到地图投影时找到官方的文档,就翻译了一下,由于英文能力差,翻译不好的地方,请看原文 原文地址:http://docs.openlayers.org/library/sp ...

  7. el-cascader 级联选择器使用时遇到的一些问题

    Element UI Cascader官网文档 <el-form-item label="章节" style="margin-right: 64px"&g ...

  8. JAVA怎样理解面向对象

    一.对象   现实世界中,随处可见的一种事物就是对象,对象是事物存在的实体,如人类.书桌.计算机.高楼大厦等.人类解决问题的方式总是将复杂的事物简单化,于是就会思考这些对象都是由哪些部分组成的.通常都 ...

  9. 【MySQL】【一】shell

    进入MySQL:mysql -u root -p 查看当前数据库下所有库:mysql> show databases; 切换到某库:mysql> use sys; 查看sys库下所有表:m ...

  10. git项目,VSCode显示不同颜色块的含义

    一. 概念 代码里的左侧颜色标识: 红色,未加入版本控制; (刚clone到本地) 绿色,已经加入版本控制暂未提交; (新增部分) 蓝色,加入版本控制,已提交,有改动: (修改部分) 白色,加入版本控 ...