B1027. 打印沙漏 (20)

Description:

本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印

*****
***
*
***
*****

所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。

给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。

Input:

输入在一行给出1个正整数N(<=1000)和一个符号,中间以空格分隔。

Output:

首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下没用掉的符号数。

Sample Input:

19 *

Sample Output:

*****
  ***
   *
  ***
*****
2

 #include <cstdio>
#include <cmath> int main()
{
int n;
char c;
scanf("%d %c", &n, &c); int bottom = (int)sqrt(2.0*(n+))-;
if(bottom% == )
--bottom;
int used = (bottom+)*(bottom+)/-;
for(int i=bottom; i>=; i-=) {
for(int j=; j<(bottom-i)/; ++j) printf(" ");
for(int j=; j<i; ++j) printf("%c", c);
printf("\n");
}
for(int i=; i<=bottom; i+=) {
for(int j=; j<(bottom-i)/; ++j) printf(" ");
for(int j=; j<i; ++j) printf("%c", c);
printf("\n");
}
printf("%d\n", n-used); return ;
}

A1031. Hello World for U (20)

Description:

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 n1characters, 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:

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:

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 <cstring> int main()
{
char str[], ans[][];
gets(str); int N = strlen(str);
int n1 = (N+)/, n3 = n1, n2 = N+-n1-n3;
for(int i=; i<=n1; ++i) {
for(int j=; j<=n2; ++j)
ans[i][j] = ' ';
} int pos = ;
for(int i=; i<=n1; ++i) ans[i][] = str[pos++];
for(int j=; j<=n2; ++j) ans[n1][j] = str[pos++];
for(int i=n3-; i>=; --i) ans[i][n2] = str[pos++];
for(int i=; i<=n1; ++i) {
for(int j=; j<=n2; ++j)
printf("%c", ans[i][j]);
printf("\n");
} return ;
}
 #include <cstdio>
#include <cstring> int main()
{
char str[];
gets(str); int N = strlen(str);
int n1 = (N+)/, n3 = n1, n2 = N+-n1-n3;
for(int i=; i<n1-; ++i) {
printf("%c", str[i]);
for(int j=; j<n2-; ++j)
printf(" ");
printf("%c\n", str[N-i-]);
}
for(int i=; i<n2; ++i)
printf("%c", str[n1+i-]); return ;
}

PAT/图形输出习题集的更多相关文章

  1. (转)用AGG实现高质量图形输出(二)

    本文上接<用AGG实现高质量图形输出(一)>,分别介绍了AGG显示流程中的各个环节. 上次讲了AGG的显示原理并举了一个简单的例子,这一篇文章开始讲AGG工作流程里的每个环节.为了方便对照 ...

  2. GIS前端将选中的图形输出为Shapfile文件

    老师让我实现如题的功能,我对着ArcGIS js api找了半天,没有发现该方法接口,找了很多资料,前后问了三个前辈. 第一个前辈说用GP服务,我在ArcMap的工具箱里找到convert to la ...

  3. C语言 · 图形输出

    算法提高 图形输出   时间限制:1.0s   内存限制:512.0MB      编写一程序,在屏幕上输出如下内容: X | X | X ---+---+--- | | ---+---+--- O ...

  4. C++笔记(7)——一些模拟题:简单模拟、查找元素、图形输出、日期处理、进制转换、字符串处理

    以下内容基本来自<算法笔记>,作者为胡凡,建议直接买书看,我这里只是摘抄部分当笔记,不完整的. 简单模拟 就是一类"题目怎么说你就怎么做"的题目.这类题目不涉及算法,只 ...

  5. PAT/字符串处理习题集(二)

    B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...

  6. PAT/查找元素习题集

    B1004. 成绩排名 (20) Description: 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. Input: 每个测试输入包含1个测试用例,格式为: 第1行: ...

  7. PAT/简单模拟习题集(一)

    B1001.害死人不偿命的(3n+1)猜想 (15) Description: 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉 ...

  8. pat 团体赛练习题集 L2-008. 最长对称子串

    对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...

  9. matplotlib简介-高质量图形输出

    Matplotlib 是一个用来绘制二维图形的 Python 模块,它克隆了许多 Matlab 中的函数, 用以帮助 Python 用户轻松获得高质量(达到出版水平)的二维图形. 文章来源:http: ...

随机推荐

  1. Spring MVC CORS support

    使用详见: https://spring.io/blog/2015/06/08/cors-support-in-spring-framework 简单用法,在Controller 方法上加 @Cros ...

  2. .net类库里ListView的一个BUG

    今天在CSDN论坛里看一个帖子,说是在ListView中添加了条目后第一行内容不显示,为了还原他的问题我写了以下代码. private void LoadFiles(DirectoryInfo dir ...

  3. mysql主从不一致解决方法

    方法一:忽略错误后,继续同步 该方法适用于主从库数据相差不大,或者要求数据可以不完全统一的情况,数据要求不严格的情况 stop slave; #表示跳过一步错误,后面的数字可变 set global ...

  4. DEV设计之自动流水号,DEV专家解答,自己折腾了半天也没有搞定,怪英文不好

    () 老外专家给了回答,结果没有全到懂,又折腾了20分钟朋友提示才搞定 获取一个自动增加1的流水号值, 第一个参数是本事的数据库连接对象,第2个参数是也这个值为唯一标识返回来一个增量的值,第三个好像没 ...

  5. matplotlib 随记

    1.安装 window平台下推荐安装Enthought canopy,包含matplotlib和它所依赖的包: linux下一般默认内置了matplotlib,直接使用就可以了.   2.在没有图形界 ...

  6. 设置secureCRT的鼠标右键为弹出文本操作菜单功能

    options菜单下的 global options 页面的 terminal 中的 mouse 子菜单对 paste  on  right button 的选项取消勾选即可.

  7. cxf+spring+数字签名开发webservice(一)

    数字证书的准备         下面做的服务端和客户端证书在例子中无法加解密,不知道什么原因,我是使用正式环境中的客户端和服务端进行开发测试的,所以需要大家自己去准备证书,或者有人知道为什么jdk生成 ...

  8. css3选择器总结

    1.p[class^/$/*=td]所有p标签的前面带有td/后面带有td/所有带有td的类的三种样式. 2.div:first-child/last-child/nth-child()在父元素下的第 ...

  9. 【线段树套平衡树】【pb_ds】bzoj3196 Tyvj 1730 二逼平衡树

    线段树套pb_ds里的平衡树,在洛谷OJ上测试,后三个测试点TLE #include<cstdio> #include<algorithm> #include<ext/p ...

  10. Oracle安装:64位电脑安装64位Oracle、PLSQL步骤

    步骤: 1.安装64位Oracle 2.安装64位PLSql 3.将11.2.0.win32的压缩包解压,放在Oracle的安装目录:product下 4.配置PLSQL参数: Tools -> ...