PAT/图形输出习题集
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/图形输出习题集的更多相关文章
- (转)用AGG实现高质量图形输出(二)
本文上接<用AGG实现高质量图形输出(一)>,分别介绍了AGG显示流程中的各个环节. 上次讲了AGG的显示原理并举了一个简单的例子,这一篇文章开始讲AGG工作流程里的每个环节.为了方便对照 ...
- GIS前端将选中的图形输出为Shapfile文件
老师让我实现如题的功能,我对着ArcGIS js api找了半天,没有发现该方法接口,找了很多资料,前后问了三个前辈. 第一个前辈说用GP服务,我在ArcMap的工具箱里找到convert to la ...
- C语言 · 图形输出
算法提高 图形输出 时间限制:1.0s 内存限制:512.0MB 编写一程序,在屏幕上输出如下内容: X | X | X ---+---+--- | | ---+---+--- O ...
- C++笔记(7)——一些模拟题:简单模拟、查找元素、图形输出、日期处理、进制转换、字符串处理
以下内容基本来自<算法笔记>,作者为胡凡,建议直接买书看,我这里只是摘抄部分当笔记,不完整的. 简单模拟 就是一类"题目怎么说你就怎么做"的题目.这类题目不涉及算法,只 ...
- PAT/字符串处理习题集(二)
B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...
- PAT/查找元素习题集
B1004. 成绩排名 (20) Description: 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. Input: 每个测试输入包含1个测试用例,格式为: 第1行: ...
- PAT/简单模拟习题集(一)
B1001.害死人不偿命的(3n+1)猜想 (15) Description: 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉 ...
- pat 团体赛练习题集 L2-008. 最长对称子串
对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...
- matplotlib简介-高质量图形输出
Matplotlib 是一个用来绘制二维图形的 Python 模块,它克隆了许多 Matlab 中的函数, 用以帮助 Python 用户轻松获得高质量(达到出版水平)的二维图形. 文章来源:http: ...
随机推荐
- JAVA学习笔记(二):eclipse智能提示(转)
存盘 Ctrl+s(肯定知道)注释代码 Ctrl+/取消注释 Ctrl+\(Eclipse3已经都合并到Ctrl+/了)代码辅助 Alt+/快速修复 Ctrl+1代码格式化 Ctrl+Shift+f整 ...
- php版本引起的const问题
刚刚遇到一个问题,类中定义了一个常量: const USER = ['aa', 'bb', 'cc']; 在类中的静态函数中调用以上常量不会出错.网站中所有的网页均能正常打开. 而当push到线上后, ...
- javascript json转为 go struct 小工具代码
/** * Created by cdpmac on 15/10/20. */ var topname="Ap"; var jdata={ "item": { ...
- 笔记本win8,mac10.10,ubuntu,android四系统安装
前言,最简单的是win8和ubuntu 最难啃的是mac android版只是要注意一个小技巧,目前算是独创 (被android坑了一次,两块硬件,android版把500Gntfs的硬盘整个识别为一 ...
- eclipse无法创建Server
报错:Cannot create a server using the selected type1.退出eclipse 2.到[工程目录下]/.metadata/.plugins/org.eclip ...
- sql脚本查询日期时间段日期
---列举指定时间月份DECLARE @date1 VARCHAR(10) , @date2 VARCHAR(10)SET @date1 = '2010-01-01'SET @date2 = '201 ...
- tfs 删除工作区
公司员工离职后,有部分文件迁出,有没有tfs密码的情况下,考虑删除工作区,在网上找到方法实践有效,在次记录下. 在命令提示行下进入 “...\Microsoft Visual Studio 8\Com ...
- Shell文本处理 - 分割合并与过滤
sort分类操作 示例文件 Boys in Company C:HK:192:2192 Alien:HK:119:1982 The Hill:KL:63:2972 Aliens:HK:532:4892 ...
- 实战录 | Kafka-0.10 Consumer源码解析
<实战录>导语 前方高能!请注意本期攻城狮幽默细胞爆表,坐地铁的拉好把手,喝水的就建议暂时先别喝了:)本期分享人为云端卫士大数据工程师韩宝君,将带来Kafka-0.10 Consumer源 ...
- 把页面上的图表导出为pdf文件,分享一种请求下载文件的方法
最近客户提出一个需求,就是把页面上的图表导出为pdf文件. 找了很多资料.终于有了点头绪.最主要是参考了HighCharts的做法.http://www.hcharts.cn/ 实现原理:把页面图表的 ...