十进制转换成任意进制(栈的应用)


#include <iostream>
#include <stack>
using namespace std;

int main()
{
	stack<char> s;
	char a[37]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int x, n;
	scanf("%d%d", &x, &n);
	if (!x)	printf("0");
	else
	{
		while (x)
		{
			int ans = x % n;
			s.push(a[ans]);
			x /= n;
		}
		while (!s.empty())
		{
			printf("%c", s.top());
			s.pop();
		}	
	}
	return 0;
}
========================================Talk is cheap, show me the code=======================================
posted @ 2018-03-14 14:38  绿叶萌飞  阅读(203)  评论(0编辑  收藏  举报