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

帮忙找错吧?why wa?谢了!

Posted by liweishun2269 at 2007-08-12 23:33:13 on Problem 1546
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	char str[8],result[50];
	int b1,b2,i,len,temp,num,flag,tt;
	while(cin>>str>>b1>>b2)
	{
		temp=0;flag=0;
		len=strlen(str);
		for(i=0;i<len;i++)
		{
			if(str[i]>='A')num=str[i]-55;
			else num=str[i]-48;
			temp+=num*pow(b1,len-i-1);
		}
		while(temp>b2)
		{
			tt=temp%b2;
			temp=temp/b2;
			if(tt>9)result[flag++]=tt+55;
			else result[flag++]=tt+48;
		}
		if(temp>9)result[flag]=temp+55;
		else result[flag]=temp+48;
		if(flag+1>7)cout<<"  ERROR"<<endl;
		else
		{
			for(i=0;i<=6-flag-1;i++)cout<<" ";
			for(i=flag;i>=0;i--)cout<<result[i];
			cout<<endl;
		}
	}
	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