| ||||||||||
| 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 | |||||||||
万恶的stl,我竟然自己写了个全排列//全排列
#include <iostream>
#include <string>
using namespace std;
string array;
int main()
{
while(cin>>array && array != "#")
{
int j,k,is_find=0;
for(j=array.size()-1;j>0;--j)
{
if(array[j]>array[j-1])
{
is_find=1;
int tempj=j;
for(k=j;k<array.size();++k)
{
if(array[k]>array[j-1] && array[k]<=array[tempj])tempj=k;
}
char t=array[tempj];
array[tempj]=array[j-1];
array[j-1]=t;
int tempnd=array.size()-1;
tempj=j;
while(tempj<tempnd)
{
t=array[tempj];
array[tempj]=array[tempnd];
array[tempnd]=t;
++tempj;
--tempnd;
}
}
if(is_find)break;
}
if(is_find)cout<<array<<endl;
else cout<<"No Successor"<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator