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& ...
随机推荐
- 关于树莓派HDMI转VGA线接显示器黑屏
经过数种折腾,找到了解决方法,在SD卡内有个config.txt文件,在其中找到“#hdmi_safe=1”,把#消除掉,变更后成为 # uncomment if you get no picture ...
- 【个人阅读作业】软件工程M1/M2总结
链接:”看<快速软件开发>的五个问题“ http://www.cnblogs.com/leiyy/p/4027759.html 一.较为明白的问题 1. 在文章的第一个关于Square_T ...
- 12.11 Daily Scrum
Today's Task Tomorrow's Task 丁辛 实现和菜谱相关的餐厅列表. 实现和菜谱相关的餐厅列表. 邓亚梅 美化搜索框UI. 美 ...
- 个人阅读作业 --软件工程M1/M2总结
软件工程M1/M2总结 写在前面的话: 这学期的软件工程伴着考期的展开逐渐落下帷幕,回顾这学期的软件工程,我感觉我的热情在一次又一次的失落中逐步消耗殆尽,每个人对于这门课的体验都会有所不同吧,可以确定 ...
- Sprint会议计划
经过饭后的宿舍激烈会议之后...... 1.我们的MASTER是组员董大为 2.这次sprint的目标是四则运算系统 3.每天例会时间地点:每天晚饭后在宿舍 4.实现四则运算的基本功能前期已经完成得差 ...
- PAT 1003 我要通过!
https://pintia.cn/problem-sets/994805260223102976/problems/994805323154440192 “答案正确”是自动判题系统给出的最令人欢喜的 ...
- 开源的CAS实现SSO
https://www.ibm.com/developerworks/cn/opensource/os-cn-cas/index.html ISC是基于CAS定制的,使用的高级的代理模式. https ...
- Docker-Compose 安装
1. 什么是Docker-Compose Compose项目来源于之前的fig项目,使用python语言编写,与docker/swarm配合度很高. Compose 是 Docker 容器进行编排的工 ...
- Oracle的简单的创建dblink以及进行数据迁移的方法
1. 创建dblink 语法如下: create public database link zhaobsh connect to lcoe739999 identified by Test6530 u ...
- linux_目录基本操作
ls命令 ls命令用来显示目标列表,在Linux中是使用率较高的命令.ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件. 语法 $ ls [选项] [目录] 选项 说明 -a 显示所有档案 ...