2 条题解

  • 0
    @ 2025-8-11 9:06:49
    /*
    3266:【例44.1】 输出二进制补码
    http://bas.ssoier.cn:8086/problem_show.php?pid=3266
    https://blog.csdn.net/zhunubi/article/details/125958260
    */
    #include<bits/stdc++.h>
    using namespace std;
    int a,b[10000],l;
    int main(){
    	cin>>a;
    	if(a>=0){	
    	while(a>0){
    	b[l++]=a%2;a=a/2;}l=32;b[l-1]=0;}else{a=abs(a);
    		while(a>0){
    			b[l++]=a%2;a=a/2;}l=32;b[l-1]=1;
    		for(int i=l-2;i>=0;i--){
    			if(b[i]==0){b[i]=1;}else{b[i]=0;}}
    		b[0]+=1;
    		if(b[0]>=2){
    			b[0]=b[0]%2;
    			for(int i=1;i<l;i++){
    				b[i]+=1;
    				if(b[i]>=2){b[i]=b[i]%2;}else{break;}}}}
    	for(int i=l-1;i>=0;i--){cout<<b[i];}
    	return 0;
    }
    
    • 0
      @ 2024-11-9 17:15:57
      #include <bits/stdc++.h>
      using namespace std;
      int n; 
      int main()
      {
          cin>>n;
          bitset<32>b(n);//32可换其他 
          cout<<b;
               return 0;
      }
      
      
      • 1

      信息

      ID
      186
      时间
      1000ms
      内存
      64MiB
      难度
      10
      标签
      递交数
      5
      已通过
      4
      上传者