| ||||||||||
| 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<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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator