2 条题解

  • 1
    @ 2025-11-7 19:56:42
    #include<bits/stdc++.h>
    using namespace std;
    int n,m,a[100000],i; 
    int main(){
    	cin >> n;
        while (n){
    	    a[++i]=n%16;
    	    n/=16;
        }
        cout << "0x";
        for(int j=i; j>=1; j--){
    	    if(a[j]<10) cout << a[j];
    	    else cout << char(a[j]-10+'A');
        }	
    	return 0;
    }
    
    • 0
      @ 2024-5-7 16:59:36
      #include<bits/stdc++.h>
      using namespace std;
      
      const int N=1e4+10;
      long long a,b,c,d,e,f,g;//b为计数器 
      string n[N];
      string sb="0123456789ABCDEF";//保存数字 
      
      int main(){
      	cin>>a;
      	cout<<"0x";//输出前缀 
      	while(a>0){
      		n[++b]=sb[a%16];
      		a/=16;
      	}
      	for(int i=b;i>=1;i--){
      		cout<<n[i];//逆序输出  
      	} 
      	return 0;
      }
      
      • 1

      [MOI周比赛] 十进制数转十六进制数

      信息

      ID
      3124
      时间
      1000ms
      内存
      256MiB
      难度
      1
      标签
      递交数
      85
      已通过
      34
      上传者