1016七分表示

1323 ワード

http://acm.nit.net.cn/showproblem.jsp?pid=1016 数字の範囲に注意して、数字と文字は3と3に変換します。
a[2]={1,2,3];printf("%s",a);123
 
	#include <stdio.h>
	#define BSIZE 36


	void print_bin(int);

	int main()
	{
		char bin[BSIZE] = {0};
		char dexn[BSIZE] = {0};
		unsigned long long  dex;
		int i;
		int k;
		while(scanf("%s",bin) == 1)
		{
			dex = 0;
			k = 0;
			for(i=0; i < BSIZE; i++)
			{
				if(bin[i] == 0) break;
				dex = dex * 2 + (bin[i]-'0');
			}

			while(1)
			{
				if(dex < 10)
				{
					dexn[k++] = dex + '0';
					break;
				}
				i = dex % 10;
				dex = dex / 10;
				dexn[k++] = '0'+i;
			}

			for(i=k-1; i >= 0; i--)
			{
				print_bin(dexn[i] - '0');
			}

			printf("
"); } return 0; } void print_bin(int digit) { switch(digit) { case 0: printf("0000");break; case 1: printf("0001");break; case 2: printf("0010");break; case 3: printf("0011");break; case 4: printf("0100");break; case 5: printf("0101");break; case 6: printf("0110");break; case 7: printf("0111");break; case 8: printf("1000");break; case 9: printf("1001");break; default : break; } }