A1031. Hello World for U
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的更多相关文章
- 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 ...
- PAT A1031 Hello World for U (20)
思路: 读取数组 int i = 0; while(cin >> word) { c[i] = word; i++; } 计算边长 int n1 = (length + 2) / 3; i ...
- A1031
画图,用二维数组作为画布 #include<cstdio> #include<string.h> int main(){ ],u[][]; scanf("%s&quo ...
- 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 ...
- PAT/图形输出习题集
B1027. 打印沙漏 (20) Description: 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ...
- 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 ...
- PAT题目AC汇总(待补全)
题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
随机推荐
- 1023 C. Bracket Subsequence
传送门 [http://codeforces.com/contest/1023/problem/C] 题意 n字符串长度,k要求的字符串的长度,字符串只包含'('和')',而且这两种的数量相等,要求的 ...
- 【2016.3.22】作业 Word count 小程序
今天更下word count程序的设计思路及实现方法. 我的程序贴在coding里,这里就先不贴出来了, 我的coding地址:https://coding.net/u/holy_angel/p/wo ...
- Flask之WSGI:Werkzeug
WSGI 一个Web应用的本质就是: 浏览器发送一个HTTP请求: 服务器收到请求,生成一个HTML文档: 服务器把HTML文档作为HTTP响应的Body发送给浏览器: 浏览器收到HTTP响应,从HT ...
- 一些调格式的经验 & 插入图注和尾注
一些调格式的经验(以Word2010为例) 1. 从目录正文分别编页码 将光标放在要重新编写页码起始页的最开始位置 分节:页面布局->分隔符->分节符(连续) 插入页码后,选中页码起始页页 ...
- 关于本科毕业论文《Laguerre小波在数值积分与微分方程数值解中的应用》存在的问题与小结
本科的毕业设计<Laguerre小波在数值积分与微分方程数值解中的应用>是通过Laguerre小波函数来近似表达某个需要求积分或解微分方程的函数,将原函数很难求得函数用小波函数表达出来,这 ...
- SQL之SELECT语句执行顺序及子句功能
1.select 语句的执行顺序 SELECT a.id,a.`product_name`,a.`agreement_copies` i,b.id as statusId from `opmp_pro ...
- 使用YII框架的migrate迁移数据库
框架版本:2.0.13 官网手册说明:http://www.yiichina.com/doc/guide/2.0/db-migrations 创建迁移 命令的格式: php yii migrate/c ...
- Linux下运行Shell脚本或者可执行文件Executable方法
绝对路径 /xxx/xxx/something.sh /xxx/xxx/executable 相对路径 ./something.sh ./executable 注意:前边得加./,可不是像window ...
- Array与Object
typeof([ ])的返回值是object,因为数组叫做数组对象. Array有length属性,而Object没有length属性,所以可以根据length属性来判断数据属于数组还是对象. Arr ...
- WorkStation 虚拟机迁移到 ESXi的后续处理.
自己遇到了然后按照blog http://blog.sina.com.cn/s/blog_79a8b8e10102w8bm.html 解决 特此记录一下. 将Workstation的vmdk文件导入到 ...