HDU 2031

863 단어 c
#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;
}

좋은 웹페이지 즐겨찾기