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

为啥我这个是WA?

Posted by 228178562 at 2009-06-22 22:47:55 on Problem 1146
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string s; 
	while (cin>>s && s!="#")
	{ 
		int i=s.size()-1;  
		bool b=true;  
		while (i>0)  
		{
			i--;  
			if (s[i]<s[i+1])
			{ 
				b=false; break; 
			}  
		} 
		if (b) 
			cout<<"No Successor"<<endl;  
		else 
		{ 
			sort(s.begin()+i, s.end()); 
			int k=1;   
			while (s[i+k]==s[i]) k++;
			swap(s[i],s[i+k]);  
			cout<<s<<endl;  
		}
	}
	
	return 0;
}


===================

#include "string.h"
#include "stdio.h"

int panduan(char a[3000])
{
	int i;
	for(i = strlen(a)-1;i != 0;i--)
	{
		if(a[i-1]<a[i])
			return i;
	}
	return 0;
}
SubString(char *src, char *dst, int offset) 
{
    int i;
	for(i=0;i < offset;i++)
	{
		dst[i]=src[i];
	}
	dst[i]='\0';
	return 0;
} 
rSubString(char *src, char *dst, int offset) 
{
    int i,a=0;
	for(i=offset;i <= strlen(src);i++)
	{
		dst[a]=src[i];
		a++;
	}
	return 0;
} 
char min(char *src)
{
	int i=0;char tempch=src[0];
	for(;src[i]!='\0';i++)
		if(tempch>src[i])
			tempch=src[i];
		return tempch;
}
sort(char *src)
{
	int i=0,j=0;char temp;
	for(;i<strlen(src);i++)
		for(j=i+1;j<strlen(src);j++)
			if(src[i]>src[j])
			{
				temp=src[i];
				src[i]=src[j];
				src[j]=temp;
			}
}
int main(int argc, char* argv[])
{
	char ch[3000],ch1[3000],ch2[3000],tem;
	int i,j;
	while(scanf("%s",ch),ch[0]!='#')
	{
		i=panduan(ch);
		if(i==0)
		{
			printf("No Successor\n");
			continue;
		}
		rSubString(ch,ch1,i);
		tem=ch[i-1];
		ch[i-1]=min(ch1);
		for(j=0;ch1[j]!='\0';j++)
		{
			if(ch1[j]==ch[i-1])
			{
				ch1[j]=tem;
				break;
			}
		}
		SubString(ch,ch2,i);
		sort(ch1);
		strcat(ch2,ch1);
		printf("%s\n",ch2);
	}
	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