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 zhuangmz at 2011-08-25 01:13:16 on Problem 2013
/*
题目说最多15个string。如果递归的话,栈的大小也应该足够了
*/
#include <iostream>
#include <string>
using namespace std;

int N;

void do_it (int n) {
	if (n == N / 2)
	{
		if (0 != N % 2) {
			string str;
			cin >> str;
			cout << str << "\n";
		}
		return ;
	}
	string str1, str2;
	cin >> str1 >> str2;
	cout << str1 << "\n";
	do_it(++n);
	cout << str2 << "\n";
}

int main()
{
	int set = 1;
	while (cin >> N) {
		if (0 == N)
			break ;
		cout << "SET " << (set++) << "\n";
		do_it(0);
	}
	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