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 luyade at 2008-03-03 21:45:01 on Problem 3359
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
using namespace std;
struct str
{
	char st[21];
	int min;
};
struct str s[21];
void searchmin(int u,int len)
{
	int i=0,temp;
	for(;i<len-1;i++)
	{
		temp=s[u].st[i]-s[u].st[i+1];
		if(s[u].min>abs(temp))
			s[u].min=abs(temp);
	}
}

int main()
{
	int pos,i,len,Max;
	char s1[21],s2[21];
	while(scanf("%s",s1)!=EOF)
	{
		for(i=0;i<21;i++)
			s[i].min=9999;
		Max=-1;
		len=strlen(s1);
		strcpy(s[10].st,s1);
		strcpy(s2,s1);
		for(i=0;i<10;i++)
		{
			prev_permutation(s1,s1+len);
			strcpy(s[i].st,s1);
		}
		for(i=11;i<21;i++)
		{
			next_permutation(s2,s2+len);
			strcpy(s[i].st,s2);
		}
		for(i=0;i<21;i++)searchmin(i,len);

		for(i=0;i<21;i++)
			if(s[i].min>Max)
			{
				pos=i;Max=s[i].min;
			}
		printf("%s%d\n",s[pos].st,s[pos].min);
	}
	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