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 speedcell4 at 2011-03-29 14:25:34 on Problem 1731
In Reply To:next_permutation 过了 Posted by:speedcell4 at 2011-03-29 14:24:26
#include<iostream>
#include<cstring>
using namespace std;
char a[200],now[200],last[200];
int v[200]={0};
int cmp(const void *a,const void *b)
{
    return *(char *)a-*(char *)b;
}
void kan(int n,int l)
{
    if(l==n&&strcmp(now,last)>0)
    {
        for(int i=0;n-i;i++)
        {
            cout<<now[i];
            last[i]=now[i];
        }
        cout<<endl;
    }
    else
    {
        for(int i=0;n-i;i++)
        {
            if(v[i]==0)
            {
                v[i]=1;
                now[l]=a[i];
                kan(n,l+1);
                v[i]=0;
            }
        }
    }
}
int main()
{
    gets(a);
    qsort(a,strlen(a),sizeof(char),cmp);
    kan(strlen(a),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