# 蓝桥试题集-基础练习-BASIC-10~13-十进制转十六进制-十六进制转十进制-十六进制转八进制-数列排序

## BASIC-10 十进制转十六进制

30

1E

#include<iostream>
#include<cstring>
using namespace std;
int  main(){
int n,i=0,t;
cin>>n;
char s[10];
if(n==0)
cout<<0;
else{
while(n){
t=n%16;
if(t>=10)
s[i++]=t%10+'A';
else
s[i++]=t+'0';
n=n/16;
}
s[i]='\0';
char ch;
int len=strlen(s);
for(i=0;i<len/2;i++){
ch=s[i];
s[i]=s[len-i-1];
s[len-i-1]=ch;
}
cout<<s;
}
return 0;
}


## BASIC-11 十六进制转十进制

FFFF

65535

#include<iostream>
#include<cstring>
using namespace std;
int  main(){
char s[10];
long long sum=0;	//注意数据类型的大小
cin>>s;
int len=strlen(s);
for(int i=0;i<len;i++){
if(s[i]>='0'&&s[i]<='9'){
sum=sum*16+(s[i]-'0');
}
if(s[i]>='A'&&s[i]<='F')
sum=sum*16+(s[i]-'A'+10);
}
cout<<sum;
return 0;
}


## BASIC-12 十六进制转八进制

【注意】

2
39
123ABC

71
4435274

【提示】

#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
cin>>n;
string s1[12],s2[12];
for(int i = 0;i<n;i++)
cin>>s1[i];
for(int i = 0;i<n;i++){
s2[i]="";
for(int j = 0;j<s1[i].length();j++){
switch (s1[i][j]) {
case '0' : s2[i] += "0000"; break;
case '1' : s2[i] += "0001"; break;
case '2' : s2[i] += "0010"; break;
case '3' : s2[i] += "0011"; break;
case '4' : s2[i] += "0100"; break;
case '5' : s2[i] += "0101"; break;
case '6' : s2[i] += "0110"; break;
case '7' : s2[i] += "0111"; break;
case '8' : s2[i] += "1000"; break;
case '9' : s2[i] += "1001"; break;
case 'A' : s2[i] += "1010"; break;
case 'B' : s2[i] += "1011"; break;
case 'C' : s2[i] += "1100"; break;
case 'D' : s2[i] += "1101"; break;
case 'E' : s2[i] += "1110"; break;
case 'F' : s2[i] += "1111"; break;
default:
break;
}
}
if(s2[i].length()%3==1)
s2[i] = "00" + s2[i];
else if(s2[i].length()%3==2)
s2[i] = "0" + s2[i];
int flag = 0;
for(int j = 0;j<=s2[i].length()-3;j+=3){
int num = 4*(s2[i][j]-'0')+2*(s2[i][j+1]-'0')+(s2[i][j+2]-'0');
if(num)
flag = 1;
if(flag)
cout<<num;
}
cout<<endl;
}
return 0;
}



## BASIC-13 数列排序

5
8 3 6 4 9

3 4 6 8 9

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,m[201];
cin>>n;
for(int i=0;i<n;i++)
cin>>m[i];
sort(m,m+n);
for(int i=0;i<n;i++)
cout<<m[i]<<" ";
return 0;
}


07-05 4792
12-19 1193
03-27 2811
05-07 611
02-20 2765
10-26 1551
10-31 2427
01-22 2584
07-18 58
11-09 487
02-27 2200
10-17 3万+
02-18 287
04-21 241
12-19 1万+