7 solutions

  • 2
    @ 2024-10-25 19:38:09

    时代变了

    #include <bits/stdc++.h>
    using namespace std;
    int x;
    int main()
    {
    	cin >> x;
    	printf("%X", x);
    	return 0;
    }
    
    • 1
      @ 2023-11-18 15:26:57

      第一个数据是0

      #include<bits/stdc++.h>
      using namespace std;
      string ans;
      int main(){
      	long long a;
      	cin>>a;
      	if(a==0){
      		cout<<0;
      		return 0;
      	}
      	while(a!=0){
      		int b=a%16;
      		if(b>=10)
      		ans+=b-10+'A';
      		else
      		ans+=char(b+48);
      		a=a/16;
      	}
      	int b=ans.length();
      	for(int i=b-1;i>=0;i--)
      	cout<<ans[i];
      	return 0;
      }
      
      • -1
        @ 2023-12-2 15:59:57
        #include<bits/stdc++.h>
        using namespace std;
        
        const string R="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//存储进制所对应的符号
        int x = 16;
        
        void tox(int n)
        {
        	if(n/x==0)//边界
        	{
        		cout<<R[n];
        		return;
        	}
        	tox(n/x);//先递归
        	cout<<R[n%x];//后输出
        }
        
        int main()
        {
        	int n;
        	cin>>n;
        	tox(n);
         	return 0;
        }
        
        • -2
          @ 2023-12-16 15:47:30
          #include<bits/stdc++.h>
          using namespace std;
          void change(int x){
          	string z="0123456789ABCDEF";//存放 
          	stack<char>k;//创建栈 
          	if(x==0){
          		cout<<'0';//0直接输出0 
          		return;
          	}
          	while(x>0){
          			k.push(z[x%16]);//否则将x%16存入栈中 
          			x/=16;
          		}
          	
          	while(!k.empty()){
          		cout<<k.top();
          		k.pop();
          	}
          }
          int main(){
          	int n;
          	cin>>n;
          	change(n);
          	return 0;
          }
          
          • -2
            @ 2023-12-6 16:59:07

            超级复杂,别用

            #include<bits/stdc++.h>
            using namespace std;
            string x;
            int z=0;
            void zhuan(int a){
                int t=16;
                while(true){
                    if(a%t<10) x[z++]=a%t+'0';
                    else if(a%t>=10) x[z++]=char(a%t-10+'A');
                    if(a/t==0) break;
                    a/=t;
                }
            }
            int main(){
                int n;
                cin>>n;
                zhuan(n);
                for(int i=z-1;i>=0;i--) cout<<x[i];
                return 0;
            }
            
            • -2
              @ 2023-11-25 15:08:56
              #include<bits/stdc++.h>
              using namespace std;
              int n;
              char a='A';//拿a来方便字符串 
              string s="";//定义s存答案 
              int main(){
              	cin>>n;
              	for(int i=0;n;i++){//循环条件其实是n!=0 
              		if(n%16>=10){//分情况列举 
              			a+=n%16-10;
              			s+=a;
              			a='A';
              		}else{
              			s+=char('0'+n%16);//注意是char类型 
              		}
              		n/=16;
              	}
              	int t=s.size();
              	for(int i=t-1;i>=0;i--) cout<<s[i];//逆序输出 
              	if(s=="") cout<<0;//第一个测试数据是0 
              	cout<<endl;
              	return 0;
              }
              
              • -2
                @ 2023-11-24 19:22:58
                #include <bits/stdc++.h>
                using namespace std;
                char i2c(int c){
                    if (c < 10) {
                        return c + '0';
                    } else {
                        return c - 10 + 'A';
                    }
                }
                void t2n(int n,int b){
                    stack<char> s;
                    if (n == 0) {
                        s.push('0');
                    } else {
                        while (n) {
                            s.push(i2c(n % b));
                            n /= b;
                        }
                    }
                	while (!s.empty()){
                		printf("%c",s.top());
                		s.pop();
                	}
                }
                int main(int argc, char **argv){
                	int n;
                	cin >> n;
                	t2n(n,16);
                	return 0;
                }
                
                • 1

                Information

                ID
                184
                Time
                1000ms
                Memory
                512MiB
                Difficulty
                7
                Tags
                # Submissions
                162
                Accepted
                36
                Uploaded By