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

求助2611,总是WA

Posted by vividx at 2006-09-27 00:01:30
Language:C++  Result:Wrong Answer

Source 

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=32;

int main(void)
{
	int left,right,curl,curr,length,len;
	char c[maxn];
	while(scanf("%s",c)!=EOF && c[0]!='.')
	{
		length=strlen(c);
		len=length-1;
		c[len-1]=c[len];
		curl=0,curr=len-1;
		left=-1,right=len;
		
		while(curl < curr)//76.7	211111.1
		{
			if(c[curr]=='2')
			{
				c[curr] = '5';
				left = right = curr;
				break;
			}
			else
				if(c[curr] == '6')
				{
						c[curr] = '9';
						left = right = curr;
						break;
				}
				else
				{
					for(int i=curr-1;i>=curl;i--)
					{
						if(c[curr] == '9')
						{
							if(c[curr] > c[i] && '6'> c[i])
							{
								c[curr] = '6';
								left = i;
								right = curr;
								curl =i;
								break;
							}
							else if(c[curr] > c[i])
							{
								left = i;
								curl = i;
								right = curr;
								break;
							}
						}
						else
							if(c[curr] == '5')
							{
								if(c[curr] > c[i] && '2' > c[i])
								{
									c[curr] = '2';
									left = i;
									right = curr;
									curl = i;
									break;
								}
								else if(c[curr] > c[i])
								{
									left = i;
									curl = i;
									right = curr;
									break;
								}
							}
							else
							{
								if(c[curr] > c[i])
								{
									curl = i;
									left = i;
									right = curr;
									break;
								}
							}
									
					}
				}
			curr--;
		}

		printf("%d\t%d\n",left,right);
		if(left == -1)//right = len
		{
			bool flag = false;
			if(c[0] == '2' || c[0] == '6')	flag = true;
			if(flag)
			{
				if(c[0] == '2') c[0] = '5';
				if(c[0] == '6')	c[0] = '9';
				for(int j = 1;j < len;j++)
				{
					if(c[j] == '5') c[j] = '2';
					else if(c[j] == '9') c[j] = '6';
				}
				sort(c+1,c+len);
				c[len] = c[len-1];
				c[len-1]='.';
				printf("%s\n",c);
			}
			else
				printf("The price cannot be raised.\n");
		}
		else
			if(left == right)
			{
				for(int j = left+1;j < len;j++)
				{
					if(c[j] == '5') c[j] = '2';
					else if(c[j] == '9') c[j] = '6';
				}
				sort(c+left+1,c+len);
				c[len] = c[len-1];
				c[len-1]='.';
				printf("%s\n",c);
			}
			//1.5
			else 
			{
				char tmp;
				tmp=c[left];
				c[left]=c[right];
				c[right]=tmp;
				for(int j=left+1;j<len;j++)
				{
					if(c[j] == '5') c[j] = '2';
					else if(c[j] == '9') c[j] = '6';
				}
				sort(c+left+1,c+len);
				c[len] = c[len-1];
				c[len-1]='.';
				printf("%s\n",c);	
			}
	}
	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