华为机试

写出一个程序,接受一个十六进制的字符串,输出该数值的十进制字符串表示。(多组同时输入 )

代码如下。注意

  1. printf的头文件是#include "stdio.h",printf("%s\n",buf);可以直接输出字符数组;
  2. 什么时候输入结束,使用while(cin>>str)判断;
  3. map的使用,使用map构造一个字典;
  4. 空字符数组的初始化方式,char buf[]={};
  5. convert包含一个输出参数,是字符数组;
  6. convert使用指针来进行移动;
  7. 使用逆转元素reverse(),它在头文件#include
    template 
    void reverse (BidirectionalIterator first, BidirectionalIterator last);
    逆转[first,last)区域的元素。
#include
#include
#include "stdio.h"
#include
#include
using namespace std;
const char dic[]="0123456789";
void convert(char buf[],int value){
    int c=0;
    char *p=buf;
    while(value>0){
        c=value%10;
        value=value/10;
        *p++=dic[c];
    }
    *p='\0';
    reverse(buf,p);
}

int main(){
    map HEX;
    char hex[]="0123456789ABCDEF";
    for(int i=0;i<16;i++){
        HEX.insert(pair(hex[i],i));
    }
    string str="";
    while(cin>>str){
        int value=0;
        for(int i=2;i

 

你可能感兴趣的:(笔试)