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. :nth-child(an+b)

    语法: :nth-child(an+b)为什么选择它,因为我认为,这个选择器是最多学问的一个了.很可惜,据我所测,目前能较好地支持她的只有Opera9+和Safari3+. 描述: 伪类:nth-ch ...

  2. 在PHP与HTML混合输入的页面或者模板中就需要对PHP代码进行闭合

    PHP程序的时候会在文件的最后加上一个闭合标签,如下: <?phpclass MyClass{public function test(){//do something, etc.}}?> ...

  3. sqlserver集合操作

    SQLServer2005通过intersect,union,except和三个关键字对应交.并.差三种集合运算 详细如下 use tempdb go if (object_id ('t1' ) is ...

  4. 【转】C#(ASP.Net)获取当前路径的方法集合

    转自:http://www.gaobo.info/read.php/660.htm //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Asse ...

  5. 【iCore3 双核心板】DEMO 1.0 测试程序发布

    iCore3 Demo V1.0 程序说明 一.概要 本资料包包含5个文件夹: 1.“arm”里是 icore3上 arm的程序包,开发环境为 KEIL 5.17: 2.“fpga”里是 icore3 ...

  6. AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

    在使用SqlConnection.Open()连接到SQL Server 2008 R2 SP2时,一直报以下异常: AccessViolationException: 尝试读取或写入受保护的内存.这 ...

  7. easyui datagrid 单选框 效果

    columns: [[{            field: 'oid',            title: '选择',            width: 20,            forma ...

  8. java IO 学习总结

    推荐文章:java I/O学习 只要是处理纯文本数据,就要优先考虑使用字符流,除此之外都用字节流 字符流:FileReader和BufferedReader的使用 String path = &quo ...

  9. Maven-006-手动部署第三方构件至 nexus 私服

    某些 Java 构件因许可证因素,无法公开的部署到公共仓库中:或者,一些小型的开源项目(例如 SourceForge.GitHub 中的一些项目),没有将构件分发到中央仓库中,也没有维护自己的仓库,因 ...

  10. iOS后台定位,实时向服务器发送最新位置

    第一步,开启后台模式,选中定位,选择project --> capabilities-->Backgorund Modes --> Location updates 如图: Past ...