其他分享
首页 > 其他分享> > 杭电2031

杭电2031

作者:互联网

#include<stdio.h>
#include<math.h>
#include<string.h>
char a[1000000];
char c[1000000];
char b[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; 
int main(void)
{
	int N,NN,R,j,flag;
	while(~scanf("%d%d",&NN,&R))
	{
		N=abs(NN);
		flag=1;
		for(int i=0;i<=strlen(a);i++)
		{
			a[i]='\0';
			c[i]='\0';
		}
			for(int i=0;;i++)
		    {
		    	if(N<R)
		    	{
		    		a[i]=b[N];
		    		j=i;
		    		break;
				}
			    else
			    {
				    a[i]=b[N%R];
				    N/=R;
			    }
		    }
		for(int i=0;i<=j;i++)
		{
			c[i]=a[j-i];
		}
		if(NN<0) printf("-");
	    for(int i=0;i<=j;i++)
		{
			if(flag==1&&c[i]==0) continue;
			else
			{
				printf("%c",c[i]);
				flag=0;
			}
		}
		printf("\n");	
	} 
	return 0;
}

标签:char,NN,int,1000000,杭电,flag,2031,include
来源: https://blog.csdn.net/qq_60656035/article/details/120489076