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. Oracle 11G在用EXP 导出时,空表不能导出解决

    Oracle 11G在用EXP 导出时,空表不能导出解决 (转)(.http://wanwentao.blog.51cto.com/2406488/545154 11G中有个新特性,当表无数据时,不分 ...

  2. 关于meta标签

    一.Meta标签中的format-detection属性及含义 意为:格式检测 或许你会有这样的经历:当你在制作手机端的页面中,点击了没有加任何链接的格式的数字时,这时手机会进行自动拔号提示操作! 禁 ...

  3. 整理分享C#通过user32.dll模拟物理按键操作的代码

    对系统模拟按键方面的知识和按键映射代码做了一下梳理,在这里分享出来,适用于开发自动操作工具和游戏外挂. 主代码: public const int KEYEVENTF_EXTENDEDKEY = 0x ...

  4. jetty服务器启动方法总结【备用】

    1. 使用Java命令启动 java -jar start.jar ctrl + c 关闭 终端窗口一直存在 2. 使用Java命令启动2 java -jar start.jar & 启动成功 ...

  5. android BluetoothLE 多个 setCharacteristicNotification writeCharacteristic 失效

    如果在搜索完服务后,执行多个 setCharacteristicNotification 或 writeCharacteristic 操作,某些操作可能会无效.需要在中间等待一些时间,真是一个大坑! ...

  6. 终端 git log 修改样式

    git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d ...

  7. SqlServer2008 无法修改表,超时时间已到 在操作完成之前超时解决方法

    在 SQL Server Management Studio 里, 通过菜单“工具-选项”打开选项对话框. 在左侧寻找“设计器-表设计器和数据库设计器”, 然后在右侧勾选“为表设计器更新重写连接字符串 ...

  8. winxp计算机管理中服务详解

    winxp计算机管理中服务详解01 http://blog.sina.com.cn/s/blog_60f923b50100efy9.html http://blog.sina.com.cn/s/blo ...

  9. Notepad++列编辑模式

    先按住alt,选中列,再上下左右拖动编辑即可:再次点击左键即可取消.

  10. 模拟n个人参加选举的过程,并输出选举结果:假设候选人有四人,分别用A,B,C,D表示,当选某候选人时,直接输入其编号(编号由计算机随机产生,若输入的不是A,B,C,D则视为无效票,选举结束后按得票数从高到底输出候选人编号和所得票数.

    模拟n个人参加选举的过程,并输出选举结果:假设候选人有四人,分别用A,B,C,D表示,当选某候选人时,直接输入其编号(编号由计算机随机产生,若输入的不是A,B,C,D则视为无效票,选举结束后按得票数从 ...