能过的
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 人评分
A+B for Input-Output Practice (IV) (C++代码)浏览:713 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:956 |
打印十字图 (C语言代码)浏览:2820 |
愚蠢的摄影师 (C++代码)浏览:980 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1483 |
1048题解(读入回车问题)浏览:628 |
C语言训练-自守数问题 (C语言代码)浏览:798 |
青年歌手大奖赛_评委会打分 (C语言代码)浏览:2248 |