Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
递归确实慢了啊!下面的程序可以优化吗?#include <iostream> #include <string> using namespace std; string cat(int x) { int i; string s,ans; if (x==0) { return (s="-"); } ans = cat(x-1); string blank(ans.size(),' '); ans = ans+blank+ans; return ans; } int main() { int t; while(1) { scanf("%d",&t); cout << cat(t); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator