| ||||||||||
| 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 | |||||||||
朴素做法,少了个等号,浪费了半小时#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator