Description

The Cantor set was discovered by Georg Cantor. It is one of the simpler fractals. It is the result of an infinite process, so for this program, printing an approximation of the whole set is enough. The following steps describe one way of obtaining the desired output for a given order Cantor set:
  1. Start with a string of dashes, with length 3order
  2. Replace the middle third of the line of dashes with spaces. You are left with two lines of dashes at each end of the original string.
  3. Replace the middle third of each line of dashes with spaces. Repeat until the lines consist of a single dash.

For example, if the order of approximation is 3, start with a string of 27 dashes:

---------------------------

Remove the middle third of the string:

---------         ---------

and remove the middle third of each piece:

---   ---         ---   ---

and again:

- -   - -         - -   - -

The process stops here, when the groups of dashes are all of length 1. You should not print the intermediate steps in your program. Only the final result, given by the last line above, should be displayed.

Input

Each line of input will be a single number between 0 and 12, inclusive, indicating the order of the approximation. The input stops when end-of-file is reached.

Output

You must output the approximation of the Cantor set, followed by a newline. There is no whitespace before or after your Cantor set approximation. The only characters that should appear on your line are '-' and ' '. Each set is followed by a newline, but there should be no extra newlines in your output.

Sample Input

0
1
3
2

Sample Output

-
- -
- - - - - - - -
- - - - 【思路】:递归题,用时稍久,希望你写出用时更短的代码。我们可以将一个数组赋值为空格,然后对该数组进行分割,同样满足题意,每次丢掉中间的三分之一,然后递归循环此过程,将其划分的更小,直到分割到长度为1,结束返回。。
#include <iostream>
#include <cmath>
using namespace std; void along(int Along)
{
if(Along<)
{
cout<<'-';
}
else
{
if(Along>=)
along(Along/);
for(int i=;i<=Along/;i++)//这儿应该是 Along/3 假如是你之前的话 打印较多的空格 你仔细看一下
cout<<" ";
if(Along>=)
along(Along/);
}
} int main()
{
int n;
while(cin>>n)
{
int Along=(int)pow(3.0,n);
along(Along);
cout<<endl;
}
return ;
}

POJ 2876 Cantoring Along的更多相关文章

  1. POJ 2876

    #include<iostream> #include<string> using namespace std; ]; int main() { //freopen(" ...

  2. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  9. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

随机推荐

  1. Java面试题大全(二)

    41.是否可以继承String类? String类是final类故不可以继承. 42.swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上? switch(expr1 ...

  2. mysql语句中有引号的问题解决方案

    在mysql的查询.修改.插入.删除的sql语句里有引号如何处理? 例如: <? $name = "my name is xcxc"; $people = "i'm ...

  3. ready是先执行的,load后执行,DOM文档的加载步骤

    在jq中在文档载入完毕后有这几种方式去执行指定函数: $(document).ready(function() { // ...代码... }); //document ready 简写 $(func ...

  4. python的内存管理机制

    先从较浅的层面来说,Python的内存管理机制可以从三个方面来讲 (1)垃圾回收 (2)引用计数 (3)内存池机制 一.垃圾回收: python不像C++,Java等语言一样,他们可以不用事先声明变量 ...

  5. EmguCV 阈值化

    一.public static double cvThreshold( IntPtr src, IntPtr dst, double threshold, double maxValue, //Max ...

  6. pomotime_v1.7.2 番茄软件完全教程

    资源下载:http://download.csdn.net/detail/xz_legendx/8546211   番茄规则和技巧 一个番茄时间共30分钟,包括25分钟的工作时间和5分钟的休息时间. ...

  7. Asp.net DropDownList 自定义样式(想怎么改就怎么改!)

    最近在做一个asp.net的项目,需要对默认的dropdownlist样式进行美化,固有的dropdownlist的小箭头实在让人无法接受,于是开始在百度,google 上下求索,天不负有心人,终于找 ...

  8. Docker-compose命令详解

    语法: Define and run multi-container applications with Docker. Usage:   docker-compose [-f=<arg> ...

  9. A B-tree index can be used for column comparisons in expressions that use the =, >, >=, <, <=, or BETWEEN operators.

    http://dev.mysql.com/doc/refman/5.7/en/index-btree-hash.html MySQL 5.7 Reference Manual  /  ...  /   ...

  10. Maven:解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.

    1.添加M2_HOME的环境变量 2.Preference->Java->Installed JREs->Edit 选择一个jdk, 添加  -Dmaven.multiModuleP ...