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

万恶的stl,我竟然自己写了个全排列

Posted by TSERROF at 2012-11-09 10:53:54 on Problem 1146
//全排列
#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:
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