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 huangsir at 2005-05-06 17:39:21 on Problem 2196
#include <iostream>
#include <queue>
using namespace std;

queue <int> q;

int decimal(int x)
{
	int residue=2147483647;//余数
	while(residue!=0)
	{
		residue=x%10;
		q.push(residue);
		x=x/10;
	}
	int sum=0;
	int i;
	while(!q.empty())
	{
		i=q.front();
		q.pop();
		sum+=i;
	}
	return sum;
}
int duodecimal(int x)
{
	int residue=2147483647;//余数
	while(residue!=0)
	{
		residue=x%12;
		q.push(residue);
		x=x/12;
	}
	int sum=0;
	int i;
	while(!q.empty())
	{
		i=q.front();
		q.pop();
		sum+=i;
	}
	return sum;
}
int hexadecimal(int x)
{
	int residue=2147483647;//余数
	while(residue!=0)
	{
		residue=x%16;
		q.push(residue);
		x=x/16;
	}
	int sum=0;
	int i;
	while(!q.empty())
	{
		i=q.front();
		q.pop();
		sum+=i;
	}
	return sum;
}

void main()
{
	int x=2991;
	int a,b,c;
	a=b=c=0;
	cout<<2992<<endl;
	while(x<=10000)
	{
		int a=decimal(x);
		int b=duodecimal(x);
		int c=hexadecimal(x);
		if(a==b&&b==c)
			cout<<x<<endl;
		x++;
	}
}

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