1 solutions
-
0
C++ :
#include <iostream> #define MAXN 1000 using namespace std; char code[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int stack[MAXN];//栈 int top = -1; //判断栈空 bool isempty(){ return top < 0; } //出栈 int pop(){ int r = stack[top]; top--;//指针下移 return r; } //入栈 void push(int value){ top++; stack[top] = value; } //转换:n转换为d进制 void conversion(int n,int d){ while(n != 0){ push(n % d); n = n / d; } } int main(){ int n,d; cin>>n>>d; conversion(n,d); if(isempty()){ cout<<0<<endl; }else{ //输出栈的内容 while(!isempty()){ cout<<code[pop()]; } cout<<endl; } return 0; }
Python :
sr=input().split() n=int(sr[0]) d=int(sr[1]) if(d==2): a=bin(n)[2:] elif(d==8): a=oct(n)[2:] elif(d==16): a=hex(n).upper()[2:] print(a)
- 1
Information
- ID
- 10411
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By