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

终于AC了,0MS水过,感谢大神的测试数据

Posted by 201501060326 at 2016-03-25 23:03:31 on Problem 1146
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    char s[100],min,t;
    int i,j,k,pd,count,len,min_int;
    while(cin>>s&&s[0]!='#')
    {
        len=strlen(s);
        for(i=len-1; i>=1; i--)
        {
            if(s[i-1]<s[i])
                break;
        }
        if(i==0)
            cout<<"No Successor"<<endl;
        else
        {
            k=i;
            count=i;
            for(i=k,min=s[k]; i<len; i++)
            {
                if(min>=s[i]&&s[i]!=s[k-1])
                {
                    min=s[i];
                    count=i;
                }
            }
            t=s[k-1];
            s[k-1]=min;
            s[count]=t;
            for(i=k,pd=count; i<len; i++)
            {
                if(s[i]<s[count])
                    pd=i;
            }
            for(i=0; i<k; i++)
                cout<<s[i];
            for(i=len-1; i>=pd&&i!=count; i--)
                cout<<s[i];
            cout<<s[count];
            for(i=pd-1; i>=k; i--)
                cout<<s[i];
            cout<<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