進制轉換
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32185 Accepted Submission(s): 17867
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
stack<int> s;
void gcd(int x,int y)
{
int r=1;
while(x) //當除數等於零的時候,則跳出循環
{
r=x%y;
s.push(r);
x=x/y;
}
}
int main()
{
int N,R,flag;
while(cin>>N>>R)
{
flag=0;
if(N<0){N=abs(N);flag=1;}
gcd(N,R);
if(flag==1)cout<<"-";
while(!s.empty())
{
if(s.top()==10)cout<<"A";
else if(s.top()==11)cout<<"B";
else if(s.top()==12)cout<<"C";
else if(s.top()==13)cout<<"D";
else if(s.top()==14)cout<<"E";
else if(s.top()==15)cout<<"F";
else cout<<s.top();
s.pop();
}
cout<<endl;
}
}