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

那位高手指点一下,代码哪里有错

Posted by egmna at 2005-09-13 01:35:10 on Problem 2611
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmp(const void *c,const void *d)
{
	return *(char*)c-*(char*)d;
}

int main()
{
	char a[50],t;
	int i,j,k,l,flag;

	while(scanf("%s",a)!=EOF&&strcmp(a,".")!=0)
	{
		l=strlen(a);
		a[l-2]=a[l-1];
		l--;
		flag=0;
		for(i=l-1;i>=0;i--)
		{
			if(a[i]=='2') {flag=1;a[i]='5';}
			else if(a[i]=='6') {flag=1;a[i]='9';}
			else for(j=i-1;j>=0;j--)
					if(a[i]>a[j])
					{
						t=a[i];
						a[i]=a[j];
						a[j]=t;
						if(a[j]=='5'&&'2'>a[i]) a[j]='2';
						if(a[j]=='9'&&'6'>a[i]) a[j]='6';
						for(k=j+1;k<=l-1;k++)
							if(a[k]=='5') a[k]='2';
							else if(a[k]=='9') a[k]='6';
						qsort(a+j+1,l-j-1,sizeof(char),cmp);
						flag=1;
						break;
					}
			if(flag) break;
		}
		l++;
		a[l-1]=a[l-2];
		a[l-2]='.';
		if(!flag) printf("The price cannot be raised.\n");
		else printf("%s\n",a);
	}
}

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