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 dynamic_study at 2009-07-15 00:45:13 on Problem 1146
#include<iostream>
using namespace std;
int main()
{
	char a[100],temp;
	int i,len,j,h,max,loop,t,flag,s;
	while(gets(a))
	{
		flag=0;
		max=999999;
		if(a[0]=='#')
			return 0;
		len=strlen(a);
		for(i=len-2;i>=0;i--)
		{
			if(a[i]<a[i+1])
			{
				flag=1;
				j=i;
				for(h=i+1;h<len;h++)
				{	if(a[h]>a[j]&&a[h]<=max)//取等于,测试数据:acbb
					{
						max=a[h];
						loop=h;
					}
				}
					temp=a[j];
					a[j]=a[loop];
					a[loop]=temp;
			//puts(a);
		//	cout<<j<<" "<<len<<endl;
			for(s=j+1,t=len-1;s<len,s<t;s++,t--)
			{
				//cout<<"s"<<s<<"t"<<t<<endl;
				temp=a[s];
				a[s]=a[t];
				a[t]=temp;
				//puts(a);
			}
			a[len]='\0';
			break;
			
			}
			

		}
		if(flag==1)
		puts(a);
		else
			cout<<"No Successor"<<endl;
	}
}

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