3 条题解

  • 1

    #include <iostream>
    using namespace std;
    bool two[32];//32位

    int pow(int a,int b){
    int ans=1;
    for(int i=1;i<=b;i++)
    ans*=a;
    return ans;
    }

    void TentoTwo(unsigned int n){
    for(int i=31;i>=0;i--)
    if(n>=pow(2,i)){
    // cout<<i<<" ";
    two[i]=1;
    n-=pow(2,i);
    }
    // cout<<endl;
    }

    void swap(bool two[]){
    for(int i=0;i<=15;i++){//two[i] two[i+16]
    bool tmp=two[i];
    two[i]=two[i+16];
    two[i+16]=tmp;
    }
    }

    unsigned int TwotoTen(bool two[]){
    unsigned int ans=0;
    for(int i=0;i<=31;i++){
    if(two[i]==1){
    // cout<<i<<" ";
    ans+=pow(2,i);
    }
    }
    // cout<<endl;
    return ans;
    }

    int main(){
    unsigned int n;
    cin>>n;
    TentoTwo(n);
    swap(two);
    cout<<TwotoTen(two)<<endl;
    return 0;
    }

  • 0
    @ 2019-11-19 23:34:59
    #include<iostream>
    using namespace std;
    int main()
    {
        long int a;
        scanf("%ld",&a);
        a=((a&65535)<<16)+((a&4294901760)>>16);
        printf("%ld\n",a);
            return 0;
    }
    

    //位运算快速编码,注意要定义long int型

  • -1
    #include<iostream>
    #include<math.h>
    using namespace std;
    class Array
    {
    private:
        int n;
        int size;
        int *a;
    public:
        Array()
        {
            size=64;
            n=32;
            a=new int[size];
        }
    
        void change_to_binary(int x)
        {
            int flag=0;
            if(x==0)
            {
                for(int i=0;i<32;i++)
                    a[i]=0;
                return;
            }
            while(x!=1)
            {
                a[flag]=x%2;
                x=x/2;
                flag++;
            }
            a[flag]=1;
            for(int i=flag+1;i<32;i++)
                a[i]=0;
        }
    
        void mirror()
        {
            int tmp;
            for(int i=0;i<=15;i++)
            {
                tmp=a[i];
                a[i]=a[31-i];
                a[31-i]=tmp;
            }
        }
    
        void swap()
        {
            int tmp;
            for(int i=0;i<=15;i++)
            {
                tmp=a[i];
                a[i]=a[i+16];
                a[i+16]=tmp;
            }
        }
    
        int change_to_decimal()//转换前要在mirror一次,便于计算
        {
            int sum=0;
            for(int i=0;i<32;i++)
            {
                sum=sum+a[i]*pow(2.0,i);
            }
            return sum;
        }
    
    
        void output()
        {
            for(int i=0;i<32;i++)
                cout<<a[i]<<" ";
        }
    
        int integration_fun(int x,Array &a)
        {
            a.change_to_binary(x);
            a.mirror();
            a.swap();
            a.mirror();
            return a.change_to_decimal();
        }
    
    };
    
    int main()
    {
        
        Array arr;
        int x;
        cin>>x;
        cout<<arr.integration_fun(x,arr)<<endl;
    
        system("pause");
        return 0;
    }
    
    
    • @ 2019-10-16 19:55:02

      缓慢打出一个"?",太大的数(像2^32-1)处理不了,有部分数据无法通过

  • 1

信息

ID
1100
难度
5
分类
模拟 点击显示
标签
(无)
递交数
103
已通过
34
通过率
33%
上传者