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. Socket入门笔记 用TcpClient实现一个简易聊天室

    效果 实现思路 使用TcpListener建一个服务器,接收所有客户端发送的消息,然后由服务器再发送到其他客户端 客户端使用TcpClient,发消息给服务器,接收服务器的消息,不和其他客户端直接交互 ...

  2. Android 安全退出应用程序的方法总结

    正常关闭应用程序: 当应用不再使用时,通常需要关闭应用,可以使用以下三种方法关闭android应用: 第一种方法:首先获取当前进程的id,然后杀死该进程. android.os.Process.kil ...

  3. 《坦克世界》1.0+:使用 CPU 优化的图形和物理丰富用户体验

    本文以<坦克世界>为例,介绍 Wargaming 使用 CPU 多核和 CPU 单指令多数据 (SIMD) 功能显著提升游戏沉浸式体验的创新方法.我们以英特尔® 线程构建模块(英特尔® T ...

  4. windows平台下编辑的内容传到linux平台出现中文乱码的解决办法

    现象说明:在windows下编辑的内容,上传到linux平台下出现中文乱码.如下: 在windows平台编写haha.txt文件,内容如下: 上传到linux平台,出现中文乱码,如下: 基本上面出现的 ...

  5. 个人博客week2

    1. 是否需要有代码规范 对于是否需要有代码规范,请考虑下列论点并反驳/支持: 这些规范都是官僚制度下产生的浪费大家的编程时间.影响人们开发效率, 浪费时间的东西. 我是个艺术家,手艺人,我有自己的规 ...

  6. 常见IP端口

    21端口:21端口主要用于FTP(File Transfer Protocol,文件传输协议)服务. 23端口:23端口主要用于Telnet(远程登录)服务,是Internet上普遍采用的登录和仿真程 ...

  7. Practise 5.2测试与封装(黑白盒

    本次测试与封装(黑白盒). 结伴队友:叶子鹏,他的博客地址:http://www.cnblogs.com/kazehanaai/ 由于我们的程序从一开始就一起弄的,所以测试的话不好换伙伴,所以我的伙伴 ...

  8. 2017[BUAA软工]第0次个人作业

    第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? ●其实填写志愿之前并不知道要学什么专业,当初选择计算机是因为计算机就业前景好.方向多.计算机应用的领域无处不在, ...

  9. 二叉排序树类的: C++ 实现

    #include<iostream> using namespace std; template<class T> struct TreeNode { T element; T ...

  10. jmeter创建基本的FTP测试计划

    这个测试计划中创建4个用户从FTP站点请求2个文件,也可以让用户重复发送2次请求,这样总请求次数=4*2*2=16 使用以下元素:thread group / FTP Request /FTP Req ...