藜麦小笼包


私信TA

用户名:dotcpp0680909

访问量:607

签 名:

刁常潇

等  级
排  名 400
经  验 5065
参赛次数 0
文章发表 66
年  龄 18
在职情况 学生
学  校 山东管理学院
专  业 软件工程

  自我简介:

一名喜欢走捷径的程序猿

TA的其他文章

能过的

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 人评分

  评论区

  • «
  • »