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 |
终于AC了,0MS水过,感谢大神的测试数据#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator