首页 > 其他 > 详细

进制(堆栈)

时间:2014-08-09 21:08:59      阅读:340      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include <iostream>
using namespace std;
#include <stack>
#include <algorithm>
int main()
{
    int i,k,n,m;
    stack<int>s;
    scanf("%d%d",&n,&m);
    while(n)
    {
        s.push(n%m);
        n=n/m;
    }
    while(!(s.empty())) 
    {if(s.top()<10)  cout<<s.top();
     else             cout<<char(A+s.top()-10); 
     s.pop();  } 
     
    cout<<endl;
    }
View Code

#include <iostream>
using namespace std;
#include <stack>
#include <algorithm>
int main()
{
int i,k,n,m;
stack<int>s;
scanf("%d%d",&n,&m);
while(n)
{
s.push(n%m);
n=n/m;
}
while(!(s.empty()))
{   if(s.top()<10)      cout<<s.top();
     else                   cout<<char(‘A‘+s.top()-10);
      s.pop();         }

cout<<endl;
}

 

 

bubuko.com,布布扣

 bubuko.com,布布扣

进制(堆栈),布布扣,bubuko.com

进制(堆栈)

原文:http://www.cnblogs.com/2014acm/p/3901446.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!