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

Re:为什么是wa啊........经测试数据验证了的啊(附代码)

Posted by yuana1 at 2010-09-28 20:29:31 on Problem 1146
In Reply To:为什么是wa啊 Posted by:yuana1 at 2010-09-28 20:26:38

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 50
void tran(char *a,char *b)
{
	int t;
	t=*a;
	*a=*b;
	*b=t;
}
void rev(char *a,int k)
{
	int i=k,j=strlen(a)-1;
	char t;
	for(;i<j;i++,j--)
	{	t=a[i];
		a[i]=a[j];
		a[j]=t;
	}
}
int main()
{
	char a[N];
	int i,j=0,k=0;
	char flag=0;
	while(scanf("%s",a)&&strcmp(a,"#"))
	{
		j=0;flag=1;
		for(i=0;a[i]!='\0';i++)
			if(a[i]<a[i+1])
			{	if(i>j)
					j=i;
				flag=1;
			}
		if(flag==0)
		{
			printf("No Successor\n");
			continue;
		}
		else
		{	k=j;
			for(i=j+1;a[i]!='\0';i++)
				if(a[j]<a[i])
					if(i>k)
						k=i;
			tran(&a[j],&a[k]);
			rev(a,j+1);
			printf("%s\n",a);
		} 
	}
	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