标签:poj rem lang 打印 pie follow code line rac
Description
---------------------------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
Output
Sample Input
0 1 3 2
Sample Output
- - - - - - - - - - - - - - -
【思路】:递归题,用时稍久,希望你写出用时更短的代码。我们可以将一个数组赋值为空格,然后对该数组进行分割,同样满足题意,每次丢掉中间的三分之一,然后递归循环此过程,将其划分的更小,直到分割到长度为1,结束返回。。
#include <iostream> #include <cmath> using namespace std; void along(int Along) { if(Along<3) { cout<<‘-‘; } else { if(Along>=3) along(Along/3); for(int i=1;i<=Along/3;i++)//这儿应该是 Along/3 假如是你之前的话 打印较多的空格 你仔细看一下 cout<<" "; if(Along>=3) along(Along/3); } } int main() { int n; while(cin>>n) { int Along=(int)pow(3.0,n); along(Along); cout<<endl; } return 0; }
标签:poj rem lang 打印 pie follow code line rac
原文地址:http://www.cnblogs.com/wft1990/p/6055916.html