博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Problem 1011 进制间的转换
阅读量:2074 次
发布时间:2019-04-29

本文共 1186 字,大约阅读时间需要 3 分钟。

Description

给你N个整数,对于每一个整数,输出它的2进制表示形式,8进制表示形式和16进制表示形式,且2进制必须以B结尾,8进制必须以0开口,16进制必须以H结尾(看样例)

Input

输入的第一行包含一个整数N(1<=N<=100),
接下来的N行,每行一个整数M(1<=M<=1000000)。

Ouput

对于给定的每个整数M,输出一样,分别为它的2、8、16进制表示形式,用空格隔开。

Sample Input

234

Sample Output

11101010B 

0352 

eaH 

#include
char s[1000000];int s1[1000000];int fun(int n,int m){ int i=0; if(m==0) return 0; while(m){ s[i]=m%n+48; m=m/n; i++; } return i;}int main(){ int t,i,m,a,j,b;    scanf("%d",&t);    for(i=0;i
=0;j--){     printf("%c",s[j]);     }     printf("B ");     a=fun(8,m); printf("0");     for(j=a-1;j>=0;j--){     printf("%c",s[j]);     }     printf(" ");     i=0;     while(m){     s1[i]=m%16;     m=m/16;     i++;     }     for(j=i-1;j>=0;j--){     if(s1[j]<10){     printf("%d",s1[j]);     }else{     switch(s1[j]){     case 10:     printf("a");     break;     case 11:     printf("b");     break;     case 12:     printf("c");     break;     case 13:     printf("d");     break;     case 14:     printf("e");     break;     case 15:     printf("f");     break;     }      }     }     printf("H\n");    }    return 0;  }

转载地址:http://gqtmf.baihongyu.com/

你可能感兴趣的文章
Leetcode C++《热题 Hot 100-24》5.最长回文子串
查看>>
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-27》17.电话号码的字母组合
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>
Leetcode C++《热题 Hot 100-40》64.最小路径和
查看>>
Leetcode C++《热题 Hot 100-41》75.颜色分类
查看>>
Leetcode C++《热题 Hot 100-42》78.子集
查看>>
Leetcode C++《热题 Hot 100-43》94.二叉树的中序遍历
查看>>
Leetcode C++ 《第175场周赛-1 》5332.检查整数及其两倍数是否存在
查看>>
Leetcode C++ 《第175场周赛-2 》5333.制造字母异位词的最小步骤数
查看>>
Leetcode C++ 《第175场周赛-3》1348. 推文计数
查看>>
Leetcode C++《热题 Hot 100-44》102.二叉树的层次遍历
查看>>
Leetcode C++《热题 Hot 100-45》338.比特位计数
查看>>
读书摘要系列之《kubernetes权威指南·第四版》第一章:kubernetes入门
查看>>
Leetcode C++《热题 Hot 100-46》739.每日温度
查看>>
Leetcode C++《热题 Hot 100-47》236.二叉树的最近公共祖先
查看>>
Leetcode C++《热题 Hot 100-48》406.根据身高重建队列
查看>>
《kubernetes权威指南·第四版》第二章:kubernetes安装配置指南
查看>>
Leetcode C++《热题 Hot 100-49》399.除法求值
查看>>