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: ...
随机推荐
- WinForm用户自定义控件,在主窗体加载时出现闪烁;调用用户控件出现闪烁,需要鼠标才能够显示
转载自:http://www.dotblogs.com.tw/rainmaker/archive/2012/02/22/69811.aspx 解决方案: 在调用用户控件的窗体里面添加一下代码: pro ...
- 2-3. Using Type Deduction
Type Deduction 发生在编译时期 可以对一般类型,自定义类型进行类型自推导 下面有两个例子: 1. Using auto with a class #include <iostrea ...
- android webview开发问题及优化汇总
我们在native与网页相结合开发的过程中,难免会遇到关于WebView一些共通的问题.就我目前开发过程中遇到的问题以及最后得到的优化方案都将在这里列举出来.有些是老生常谈,有些则是个人摸索得出解决方 ...
- Getting Started With Hazelcast 读书笔记(第八章-第十章)
第八章到第十章就是一些介绍性的描述,吹的就是Hazelcast能使用在各种地方.. 第八章 -从外面看 1.Hazelcast做了一个memcache的java实现,方便py和php使用. 2.可 ...
- 123. Best Time to Buy and Sell Stock (三) leetcode解题笔记
123. Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the pric ...
- CVTE实习面经
一个月的实习都结束了,我才把这篇面经放出来...可能有记得不太清楚的地方,还请多多见谅. 第一次面试是在5月中旬. 这次面试问的主要是基础的问题吧,就是C和C++的基础问题,我记得有问到下面几个问题 ...
- Hibernate+jsp+struts+spring做增删该查,
同样还是web项目,这里只做了一张表,做一个测试,例子.主要是建Hibernate 的时候要非常注意,有时间了整理一下建Hiberbnate 的时候需要注意的事项 这里我是建了5个包,其实只要四个就好 ...
- html之间的传值
传值:window.location.href=“eidit.html?activityId=“+acytivityIDd: 将id放进地址栏传到另一html页面 接受 再用var str=wind ...
- 对于大数据量的Json解析
近几天做了一个项目,需要解析大量的json数据,有一万多条,以前我用的都是Gson包去自动解析,但是速度真是不敢恭维,于是我又去查了其它的方法,发现fastjson的解析,发现速度直的是很快,在此我不 ...
- knapsack problem 背包问题 贪婪算法GA
knapsack problem 背包问题贪婪算法GA 给点n个物品,第j个物品的重量,价值,背包的容量为.应选哪些物品放入包内使物品总价值最大? 规划模型 max s.t. 贪婪算法(GA) 1.按 ...