Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

递归确实慢了啊!下面的程序可以优化吗?

Posted by sicheng at 2006-07-21 10:25:22 on Problem 2876
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator