1 条题解

  • 0
    @ 2025-8-11 9:11:25
    #include <iostream>
    using namespace std;
     
    long long n, x;
    string s;
    string t = "0123456789ABCDEF";
     
    int main(){
    	/*
    		条件: 
    			n是一个不超过18位的正整数。 
    		注意:
    			int最多表达到 2^31 - 1,10位整数。 
    			long long 最多表达到 2^63 - 1,19位整数。
    		
    		思路:
    			逆序存储到字符串时要注意:
    			整数 0 ~ 9,转换为字符 '0' ~ '9',x + '0' 
    			整数 10 ~ 15,转换为字符 'A' ~ 'F',x + 'A' - 10 或 x + 55 
    	*/
    	cin >> n;
    	
    	while(n != 0){
    		x = n % 16;
    		// 将 n % 16 转换为字符逆序存入 s 
    		s = t[x] + s;
    		n = n / 16;
    	}
     
    	if(s == ""){
    		cout << 0; 
    	}else{
    		cout << s;
    	}
    }
    
    • 1

    信息

    ID
    184
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    6
    已通过
    2
    上传者