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. Nuget EPPlus的使用

    EPPlus:网站 Supported Functions Excel Merge Operate public class ExcelMergeOperate { private static Lo ...

  2. 简易Samba服务器配置

    Samba的作用是在Linux和windows之间通过网络进行资源共享.下面是简单的一个文件共享例子: 1.安装samba.samba-client服务 yum install samba samba ...

  3. HDU 6203 ping ping ping(dfs序+LCA+树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意: n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V 无法连 ...

  4. android activity全屏

    有两种方法: 1.在AndroidManifest.xml的配置文件里面的<activity>标签添加属性: android:theme="@android:style/Them ...

  5. JsonKey小写

    System.Text.RegularExpressions.MatchCollection ms = System.Text.RegularExpressions.Regex.Matches(eca ...

  6. gulp常用方法

    var gulp = require('gulp'); var concat = require('gulp-concat'); //使用gulp-concat合并文件,减少网络请求(静态资源数量): ...

  7. hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Prob ...

  8. maven 引入外部jar包的几种方式

    方式1:dependency 本地jar包 <dependency> <groupId>com.hope.cloud</groupId> <!--自定义--& ...

  9. 使用ajax判断登录用户名

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx. ...

  10. PostgreSQL 扩展开发基础教程

    搭建基础结构 安装扩展 sudo apt-get install postgresql-contribcreatedb stupsql stucreate extension pg_buffercac ...