60pts???

B3849 [GESP样题 三级] 进制转换

44i11 @ 2023-11-26 14:39:13

#include<bits/stdc++.h>
#define ll long long
using namespace std;
string c="0123456798ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void f(int x,int m){
    if(x/m) f(x/m,m);
    cout<<c[x%m];
}
int main(){
    int x,m;
    cin>>x>>m;
    f(x,m);
    return 0;
}

by C_plus_plus_12345 @ 2023-11-26 14:42:03

#include<iostream>
using namespace std;
void TurnData(int n, int a);
unsigned long long V; 
int f;
char ttfif[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
int main()
{
    cin >> V >> f;
    TurnData(V, f);
    return 0;
}
void TurnData(int n, int a)
{
    int x[17], i, j, k = 0;
    if (n < 0)
    {
        cout << "-";
    }
    j = abs(n);
    do
    {
        k++;
        i = j % a;
        j /= a;
        x[k] = i;
    }
    while (j != 0);
    for (int h = k; h >= 1; --h)
    {
        if (x[h] < 10)
        {
            cout << x[h];
        }
        else
        {
            cout << ttfif[x[h] - 10];
        }
    }
    cout << endl;
}
//Everything is possible.

我的想法


by 44i11 @ 2023-11-26 14:44:39

@C_plus_plus_12345 dalao,能告诉我哪错了吗???


by 潘德理2010 @ 2023-11-26 14:50:44

@44i11 你代码里的数字顺序为什么是 0123456798


by 潘德理2010 @ 2023-11-26 14:51:19

改好就过了。


by 44i11 @ 2023-11-26 14:57:24

@潘德理2010 Thank you


by suzakudry @ 2024-03-13 19:17:02

#include<stdio.h>
char a[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
void convert(int x,int n){
    if(x==0)
        return;
    convert(x/n,n);
    printf("%c",a[x%n]);
}
int main(){
    int x,n;
    scanf("%d%d",&x,&n);  
    if(x==0)
        printf("0");
    else
        convert(x, n);
    printf("\n"); 
    return 0;
}

跟你写的类似,过了。可能是递归出口的问题吧?


by suzakudry @ 2024-03-13 19:20:20

666为什么是 0123456798?


by liuqishuo @ 2024-04-01 20:28:10

?


by hujunyi66 @ 2024-05-10 08:42:38

...................................


by minisj @ 2024-06-12 19:43:26

@44i11 @suzakudry 因为多了数字


| 下一页