赞
踩
注意0时的情况
- #include <iostream>
- using namespace std;
- char ans[100];
- char chr[] = {'A','B','C','D','E','F'};
- int main(){
- int a,k = 0;
- cin>>a;
- if(a == 0) cout<<"0"<<endl;
- while(a > 0){
- int yu = a % 16;
- a = a / 16;
- if(yu < 10){
- ans[k++] = (char)yu + '0';
- }else{
- // cout<<chr[yu - 10]<<endl;
- ans[k++] = chr[yu - 10];
- }
- }
- for(int j = k - 1; j >= 0; j--){
- cout<<ans[j];
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。