HDU 2031

 
#include<iostream>
using namespace std;
int main()
{
	int n,r;
	char result[35];
	const char alpha[6] = {'A','B','C','D','E','F'};
	while(cin>>n>>r)
	{
		bool zeng = true;
		if(n < 0)
		{
			zeng = false;
			n = -n;
		}
		memset(result,0,sizeof(result));
		int i=0;
		while(n != 0)
		{
			int temp = n%r;

			if(temp > 9)			
				result[i++] = alpha[temp%10];			
			else
				result[i++] = temp + '0';			
			
			n /= r;
		}
		if(!zeng)
			cout << "-";

		for(int j=i-1; j>=0; j--)
			cout << result[j];
		cout << endl;
	}
	return 0;
}

你可能感兴趣的:(c)