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 ACM_henry at 2008-03-07 20:16:07 on Problem 1350
#include <iostream>
#include "map"
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
	map<int,int>my;
	int p[4];
	int a;
	int i;
	int sum1,sum2;
	int num;
	int xxx;
	while(cin>>a&&(a!=-1))
	{
		//memset(p,-1,sizeof(p));
		num=0;
		my.clear();
		sum1=sum2=0;
 		
		if(a>9999||a<1000)
		{
			cout<<"No!!"<<endl;
			continue;

		}
		my[a]=1;
		cout<<"N="<<a<<":"<<endl;
	
	
		for(;;)
		{
			sum1=sum2=0;
			if(a>999)
			{
				xxx=4;
				goto there;
			}
			if(a>99)
			{
				xxx=3;
				goto there;
			}
			if(a>9)
			{
				xxx=2;
				goto there;
			}
			if(a>0)
			{
				xxx=1;
			}
there:	for(i=0;i<xxx;i++)
			{
				p[i]=a%10;
				a=a/10;
			}
			p[i]=a;
			sort(p,p+xxx);
			for(i=0;i<xxx;i++)
			{
				sum1+=p[i]*pow(10,i);
				sum2+=p[i]*pow(10,xxx-1-i);
			}
			a=sum1-sum2;
			if(my[a]==1||(a==0&&num==0))
			{
				break;
				
			}
				cout<<sum1<<"-"<<sum2<<"="<<sum1-sum2<<endl;
				my[a]=1;
				num++;

		}
		if(num==0)
		{
			cout<<"No!!"<<endl;
		}
		else cout<<"Ok!!"<<' '<<num<<' '<<"times"<<endl;
		//cin>>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