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 Icanmey at 2008-11-17 15:50:02 on Problem 1731
#include<iostream>
#include<algorithm>
using namespace std;
void print(char* c,char* s);
int main()
{
	char s[201];
	char tt[201]="\0";
	while(cin>>s)
		print(tt,s);
	return 0;
}
void print(char* c,char *s)
{
	int lenth=strlen(s);
	int lenthc=strlen(c);
	sort(s,s+lenth);
	if(lenth==1)
	{
		cout<<c<<s<<endl;
		return ;
	}
	int i,j,k=0;
	char* temp = new char [lenth];
	for(i=0;i<lenth;i++)
	{
		c[lenthc]=s[i];
		c[lenthc+1]='\0';
		for(j=0;j<i;j++)
			temp[k++]=s[j];
		for(j=i+1;j<=lenth;j++)
			temp[k++]=s[j];
		print(c,temp);
		c[lenthc]='\0';
		k=0;
		char tc = s[i];
		while(s[i]==tc)
			i++;
		i--;
	}
}

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