进制转换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 63039 Accepted Submission(s): 34261
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Swap(a,b,t) t=a,a=b,b=t
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x));
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f;
const double eps=1e-12;
stack <int> q;
int main()
{
int n,d;
while (cin>>n>>d){
while (!q.empty())
q.pop();
if (n<0){
cout<<"-";
n=-n;
}
else if (!n){
cout<<'0'<<endl;
continue;
}
while (n){
q.push(n%d);
n/=d;
}
while (!q.empty()){
int x=q.top();
if (x>=10)
printf("%c",'A'+x-10); //cout<<'A'+x-10<<endl; 这个地方有坑, 这里 cout 输出的不是字符,而是整数.
else
cout<<x;
q.pop();
}
cout<<endl;
}
return 0;
}