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

555555555.测试都对的 提交又WA。。。求救!!!!

Posted by 4053040 at 2009-12-11 08:01:06 on Problem 1546
#include<iostream>
#include<cmath>
#include<string>
#include<iomanip>
//const int A=10,B=11,C=12,D=13,E=14,F=15;
using namespace std;


int main()
{
	char x[8];
	int a,b;
	int s,i,len,qq,rr;
	int c[100];//数组开大了点
	while(scanf("%s%d%d",x,&a,&b)!=EOF)//while(scanf("%s%,d,%d",x,&a,&b)!=EOF) 貌似不能加逗号
	{
		s=0;
		memset(c,0,sizeof(0));
		len=strlen(x);
		if(len>7)
		{
			cout<<"  ERROR"<<endl;
			continue;
		}

		for(i=0;i<len;i++)
		{
			if(x[len-i-1]=='A'||x[len-i-1]=='B'||x[len-i-1]=='C'||x[len-i-1]=='D'||x[len-i-1]=='E'||x[len-i-1]=='F')
				s=s+(x[len-i-1]-'7')*pow(float(a),i);//使用'7'是为了弄出ABCDEF(根据ASCII码来的)
			else
				s=s+(x[len-i-1]-'0')*pow(float(a),i);
		}
		qq=s;//下面用到
		//cout<<s<<endl;//  s是十进制形式 至此 已经转化为十进制形式

		for(i=0;;i++)
		{	
			if(s<1) break;
			s=s/10;
		}

		for(i=0;qq>=1;i++)
		{
			c[i]=qq%b;
			//cout<<c[i]<<" ";
			//printf("%X\n",c[i]);
			qq=qq/b;
			rr=i;
        }
		
		if(rr>7)
		{
			cout<<"  ERROR"<<endl;
			continue;
		}
		cout<<setw(7-rr);//设置域宽为7 输出空格就为7-rr
		for(i=rr;i>=0;i--)
		{
			if(c[i]==10) cout<<"A";
			else if(c[i]==11) cout<<"B";
			else if(c[i]==12) cout<<"C";
			else if(c[i]==13) cout<<"D";
			else if(c[i]==14) cout<<"E";
			else if(c[i]==15) cout<<"F";
			else
			cout<<c[i];
			//printf("%X",c[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