栈实现N进制转换

^_^十进制转N进制  ——by Moshow魔手

理论上支持2~35进制!1和36进制不可用!

摆脱2~16进制的束缚


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

void ToN(int n,int x) 
{
   stack<int> stk;
   char mo[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
   int ch;
   int k = n;
   while (k) 
   {
      ch = k % x;
      stk.push(ch);
      k=k/x;
   }
   while(!stk.empty()) 
   {
	  cout<<(char)mo[stk.top()];
      stk.pop();
   }
   cout<<endl;
   
}


int main() //Moshow魔手
{
   int n,x;
   cout<<"==============================="<<endl;
   cout<<"=======十进制转换为N进制======="<<endl;
   cout<<"====  Powered by  Moshow魔手==="<<endl;
   cout<<"==============================="<<endl<<endl<<endl;
   cout<<"请输入一个十进制数:"; 
   cin>>n;
   cout<<"==============================="<<endl<<endl;
   cout<<"请输入转换为n进制:";
   cin>>x;
   cout<<"==============================="<<endl<<endl<<"输出结果为:";
   ToN(n,x);
   system("pause");
}



已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页