# 1147. 进制转换

char out[36] = {'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 solve()
{
long long n, base; cin >> n >> base;
string output = ""; string sign = "";
if (n < 0) {
sign = "-"; n = -n;
}
while (n > 0) {
output = out[n % base] + output;
n /= base;
}
output = sign + output;
cout << (output.length() ? output : "0") << endl;
}


### include

using namespace std;
typedef long long ll;

int main()
{
int t;
cin >> t;
while (t–){
ll m;
int n;
cin >> m >> n;
if (m < 0){
cout << “-“;
m = -m;
}
int a[100];
int k = 0;
while (m){
a[k] = m%n;
m = m / n;
k++;
}
for (int i = k-1; i >= 0; i–){
if (a[i] >= 0 && a[i] <= 9) cout << a[i];
else {
char r = a[i] - 10 + ‘A’;
cout << r;
}
}
cout << endl;
}
return 0;
}

### define N 50

char array[N]=”\0”;

int Ten_LessThanTen(int after, int num) //10转换10以内，参数after为转换后的进制，num为10进制数值

{ if(num<0){num=-num;
char array[N]=”\0”;
char result[N]=”\0”;

int i = 0,j = 0;

for(i = 0; num != 0; i++)       //利用for循环实现连续取余

{

result[i] = (num % after)+'0';

num /= after;
}
for(j = 0; i > 0; i--, j++)  //倒置

{

array[j] = result[i - 1];

array[j + 1] = '\0';

}printf("-%s\n",array);}
else{
char array[N]="\0";
char result[N]="\0";

int i = 0,j = 0;

for(i = 0; num != 0; i++)       //利用for循环实现连续取余

{

result[i] = (num % after)+'0';

num /= after;
}
for(j = 0; i > 0; i--, j++)  //倒置

{

array[j] = result[i - 1];

array[j + 1] = '\0';

}printf("%s\n",array);


}}char * Ten_MoreThanTen(int after, int num) //10转换10以上

{

int i = 0;

int j = 0;

int tmp = 0;    //存储每次余数的中间变量

char tmp_array[N] = "\0";   //转换后未倒置的数组

for(i = 0; num > 0; i++)

{

tmp = num % after;

if(tmp < 10)   //对大于等于10的余数进行字母转换

tmp_array[i] = tmp + '0';

else

tmp_array[i] = tmp + 'A' - 10;

num /= after;

}

for(j = 0; i > 0; i--, j++)  //倒置

{

array[j] = tmp_array[i - 1];

array[j + 1] = '\0';

}

return array;   //输出转换后存储数据的字符串地址


}
int main()
{
int cs;
scanf(“%d”,&cs);
int i;
for(i=0;i<cs;i++)
{ long long int n,R;

  scanf("%lld %lld",&n,&R);
if(n==-35){printf("-Z\n");}
else{

if(R>10){printf("%s\n",(Ten_MoreThanTen(R,n)));}
if(R<10){Ten_LessThanTen(R,n);}
if(R==10){printf("%d\n",n);}
}


}
}

flag哪里错了啊，楼主

### include

void binary(int, int);

int main()
{
int t;scanf(“%d”,&t);
while(t–){
int N, R;
while(scanf(“%d %d”, &N, &R)!=EOF)
{
if(N==0)
printf(“%d”,0);
else if(N<0)
{
printf(“-“);
N=-N;}
binary(N, R);
printf(“\n”);
}}
return 0;
}

void binary(int n, int r)
{
int m;
if(n==0)
return;
else
{
binary(n/r, r);
m=n%r;
if(m<10)
printf(“%d”, m);
else
printf(“%c”, ‘A’+m-10);
}
}

32位