Cantoring Along pku2876
来源:互联网 发布:知乎周刊在线阅读 编辑:程序博客网 时间:2024/05/18 00:52
Cantoring Along
Time Limit:1000MS Memory Limit:65536K
Total Submit:1310 Accepted:788
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:
Start with a string of dashes, with length 3order
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.
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
-
- -
- - - - - - - -
- - - -
Source
Mid-Atlantic 2002
using namespace std;
int a[16];
void Init()
...{
a[0]=1;
int i;
for(i=1;i<=12;i++)
a[i]=a[i-1]*3;
}
int main()
...{
Init();
int i,n;
while(cin>>n)
...{
for(i=0;i<a[n];i++)
...{
int k=i;
while(k%3!=1&&k)
...{
k/=3;
}
if(k) cout<<" ";
else cout<<"-";
}
cout<<endl;
}
return 0;
}
- Cantoring Along pku2876
- POJ 2876 Cantoring Along 递归
- CSDN along blog
- living me along
- br come along
- crystal reporter along with QT
- War we take all along
- [Matlab] Walking along a path
- start up along with tomcat
- Along with the social development
- 弧形文字text along path
- Ever run along wet sand
- Using JavaScript Along with ASP.NET
- Using JavaScript Along with ASP.NET
- across &through &over &cross &pass%along
- Printing ALV along with Page numbers
- Ping to Determine MTU along a route
- 2106 Problem F Shuffling Along
- HTTP HEADER 格式
- Hibernate应用(一):第一个Hibernate应用程序
- 关于生活
- 在DataGrid中添加Radio(单选按钮)列
- linux环境下cpu利用率的计算
- Cantoring Along pku2876
- C#的6种常用集合类大比拼
- mediawiki扩展:使用本地资源批量上传图片
- CString常用方法
- delphi+java三层开发架构系统的实现
- 画带阴影效果的文字
- 服务器性能监控之WMI
- 实际项目中配置SSL实例之一 SSL术语解释(共4篇)
- EditPlus配置完美的C#运行环境