2 条题解

  • 1
    @ 2024-12-1 14:23:26
    1. 二进制
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	stack<int> st;
    	int n;
    	cin>>n;
    	while(n){
    		st.push(n%2);
    		n/=2;
    	}
    	while(!st.empty()){
    		cout<<st.top();
    		st.pop();
    	}
    	return 0;
    }
    
    
    1. 八进制
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	stack<int> st;
    	int n;
    	cin>>n;
    	while(n){
    		st.push(n%8);
    		n/=8;
    	}
    	while(!st.empty()){
    		cout<<st.top();
    		st.pop();
    	}
    	return 0;
    }
    
    1. 十六进制
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	stack<int> st;
    	int n;
    	cin>>n;
    	while(n){
    		st.push(n%16);
    		n/=16;
    	}
    	while(!st.empty()){
    		if(st.top()>=10){
    			cout<<char(st.top()-10+'A');
    		} 
    		else{
    			cout<<st.top();
    		}
    		st.pop();
    	}
    	return 0;
    }
    
    • 1
      @ 2024-11-24 14:47:57
      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	stack<int> st;
      	int n;
      	cin>>n;
      	while(n){
      		st.push(n%2);
      		n/=2;
      	}
      	while(!st.empty()){
      		cout<<st.top();
      		st.pop();
      	}
      	return 0;
      }
      
      • 1

      信息

      ID
      269
      时间
      1000ms
      内存
      256MiB
      难度
      3
      标签
      递交数
      22
      已通过
      20
      上传者