能过的
def solve(a, n): temp = a if a < 0: a = -a stack = [] while a != 0: stack.append(a % n) a = a // n if temp < 0: print('-', end='') while stack: top = stack.pop() if top == 10: print('A', end='') elif top == 11: print('B', end='') elif top == 12: print('C', end='') elif top == 13: print('D', end='') elif top == 14: print('E', end='') elif top == 15: print('F', end='') else: print(top, end='') while True: try: a, n = map(int, input().split()) if a == 0: print(0) else: solve(a, n) print() except EOFError: break
不能过的
#include<bits/stdc++.h> using namespace std; #define int long long stack<int>q; void solve(int a,int n) { int temp; if(a<0) { temp=a; a=-a; } while(a!=0) { q.push(a%n); a=a/n; } if(temp<0) cout<<'-'; while(!q.empty()) { switch(q.top()) { case 10:cout<<'A';break; case 11:cout<<'B';break; case 12:cout<<'C';break; case 13:cout<<'D';break; case 14:cout<<'E';break; case 15:cout<<'F';break; default:cout<<q.top(); } q.pop(); } } signed main() { int a,n; while(cin>>a>>n) { if(a==0) cout<<0; else solve(a,n); cout<<endl; } return 0; }
大佬们有没有c++过的,求大佬的思路
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:483 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:676 |
DNA (C语言描述,蓝桥杯)浏览:1647 |
1124题解浏览:623 |
核桃的数量 (C语言代码)浏览:893 |
1071题解浏览:574 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:610 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:330 |
A+B for Input-Output Practice (II) (C语言代码)浏览:619 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1352 |