进制(堆栈)

#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;
}

 

 

 

posted @ 2014-08-09 19:00  2014acm  阅读(139)  评论(0编辑  收藏  举报