Given any string of N (>=5) 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 n1 characters, then left to right along the bottom line with n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 - 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<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
int main(){
char str[], print[][];
int len, n1, n2, n3;
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
print[i][j] = ' ';
scanf("%s", str);
len = strlen(str);
n1 = n3 = (len + ) / ;
n2 = len + - n1 - n3;
int i;
for(i = ; i < n1; i++){
print[i][] = str[i];
}
for(int j = ; j < n2; j++, i++){
print[n1 - ][j] = str[i];
}
for(int k = n1 - ; k >= ; k--, i++){
print[k][n2 - ] = str[i];
}
for(int j = ; j < n1; j++){
for(int k = ; k < n2; k++)
printf("%c", print[j][k]);
printf("\n");
}
cin >> i;
return ; }

总结:

1、打印输出题两种方法,先将其处理在二维字符数组中再逐行输出。或者直接按规律打印输出。根据题意找规律很重要。

2、涉及到字符数组处理时可以使用string.h

A1031. Hello World for U的更多相关文章

  1. A1031 Hello World for U (20)(20 分)

    A1031 Hello World for U (20)(20 分) Given any string of N (>=5) characters, you are asked to form ...

  2. PAT A1031 Hello World for U (20)

    思路: 读取数组 int i = 0; while(cin >> word) { c[i] = word; i++; } 计算边长 int n1 = (length + 2) / 3; i ...

  3. A1031

    画图,用二维数组作为画布 #include<cstdio> #include<string.h> int main(){ ],u[][]; scanf("%s&quo ...

  4. PAT甲级——A1031 Hello World for U

    Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For ...

  5. PAT/图形输出习题集

    B1027. 打印沙漏 (20) Description: 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ...

  6. 1031 Hello World for U (20 分)

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

  7. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  8. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. slurm.conf系统初始配置

    #slurm集群配置 ##集群名称 ClusterName=myslurm ##主控制器的主机名 ControlMachine=node11 ##主控制器的IP地址 ControlAddr=192.1 ...

  2. [原]Veracrypt使用Yubikey作为安全令牌

    今天刚刚到货Yubikey 5 美亚 直邮 ,易客满国际,国内居然是顺丰配送,点个赞. 必备的控件 https://developers.yubico.com/yubikey-manager-qt/R ...

  3. Spring AOP不起作用原因

    一.直接在切面类定义切点: AOP切面类里面的方法全部不支持触发切面,否则一个切面函数把自己当做切点就会导致递归层层调用. AOP切面类发出函数调用一律不触发切面,避免两个切面类相互调用迭代请求的情况 ...

  4. mongo java 踩坑记

    为什么会有这么多坑 1.  Java会把 id:String = "合法ObjectId"  好心好意的 转为  _id:ObjectId 类型. 2. 为了避免第1点, 我定义了 ...

  5. Linux课题实践三——程序破解

    2.3   程序破解 20135318 刘浩晨 1.     掌握NOP.JNE.JE.JMP.CMP汇编指令的机器码 NOP:NOP指令即“空指令”.执行到NOP指令时,CPU什么也不做,仅仅当做一 ...

  6. Sprint 冲刺第三阶段第6-10天

    这几天一直都在整理我们之前的内容,检查会不会有细节问题.例如界面跳转.颜色等. 因为一直没办法找到guitub存放位置.于是在这里存放一些主代码. MainActivity.java package ...

  7. chrome启用flash不询问

    69版本之后 打开 chrome://flags/#enable-ephemeral-flash-permission 把它从Default改为Disabled 重新打开Chrome,进入 chrom ...

  8. PAT 1021 个位数统计

    https://pintia.cn/problem-sets/994805260223102976/problems/994805300404535296 给定一个k位整数N = d~k-1~*10^ ...

  9. __new__ __init__区别

    1 class A(object): 2 def __init__(self,*args, **kwargs): 3 print "init A" 4 def __new__(cl ...

  10. 关于WrapPanel和RadioButton相互配合使用实WrapPanel现动态添加或删除项

    最近在做一个项目的时候,有一个需求就是,通过RadioButton来控制一行内容的显示与不显示,当不显示的时候,下面的项能够占住相应的位置,当增加的时候,又会在原来的位置重新显示,如果使用一般的Gri ...