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 adang at 2005-11-11 21:42:51 on Problem 1546
#include<stdio.h>

#include<string.h>

int main()
{
	char n[100];

	int i, j;

	char m[8];
	
    m[7]='\0';

	while(scanf("%s%d%d", n, &i, &j) ==3)
	{
		int g=strlen(n);

		int sum=0;

		int k=1;

	for(int y=0; y<7;  y++)
	{
		m[y]=' ';

	}

		for(int q=g-1; q>=0; q--)
		{
			if(n[q]<='9'&&n[q]>='0')
			{
			sum+=k*(n[q]-48);
			k*=i;
			}
			else
			{
				int w=0;

				switch(n[q])
				{
				case 'A': w=10;break;
				case 'B': w=11; break;
				case 'C': w=12; break;
				case 'D': w=13; break;
				case 'E': w=14; break;
				case 'F': w=15; break;
				default : break;
				}
	          sum+=k*w;
			  k*=i;
			}
		}


	
			for(int t=6; t>=0; t--)
			{
				

				int p=sum%j;

				if(p<=9)

				m[t]=sum%j+48;

				else
					switch(p)
				{
					case 10: m[t]='A';break;
					case 11: m[t]='B'; break;
					case 12: m[t]='C'; break;
					case 13: m[t]='D'; break;
					case 14: m[t] = 'E'; break;
					case 15: m[t]='F'; break;
					default : break;
				}
              if(sum<j)break;
				sum=sum/j;
			}

			if(sum>=j)
				printf("  ERROR\n");

			else
				printf("%s\n", m);
	}
	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