洛谷 数学进制 7.9

P1100 高低位交换 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

代码一
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const ll N=1e5+10;
char a[N];

int main()
{
    IOS;
    ll a;
    int b[32]={0},c[32]={0},d[32]={0};
    cin>>a;
    for(int i=31;i>=0;i--)
    {
        d[i]=a%2;
        a/=2;
        b[i]=d[31-i];
        cout<<b[i];
    }
    //cout<<"here"<<endl;
    for(int i=31;i>=0;i--)
    {
        if(i>=16 && i<=31)
        {
            
            c[i-16]=b[i];

        }

        else if(i>=0 && i<=15)
        {
            c[i+16]=b[i];
        }
    }
    ll ans=0;
    for(int i=0;i<=31;i++)
    {
        ans+=c[i]*pow(2,i);
    }
    cout<<ans<<endl;
    return 0;
}
ac代码

好简洁!!

#include<bits/stdc++.h>
typedef long long ll;

#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const ll N=1e3;
using namespace std;

int main()
{
    IOS;
    
    ll x;
    cin>>x;
    cout<<((x&0x0000ffff)<<16|(x&0xffff0000)>>16)<<endl;
    
    
    return 0;
}

相关推荐

  1. P2084】转换 题解(模拟+字符串)

    2024-07-10 08:34:02       50 阅读
  2. 每日一题 第十一期 转换

    2024-07-10 08:34:02       41 阅读
  3. (二).数值&转换

    2024-07-10 08:34:02       39 阅读
  4. 击的奶牛

    2024-07-10 08:34:02       60 阅读
  5. 阶乘数码#

    2024-07-10 08:34:02       82 阅读
  6. 数字反转(升级版)#

    2024-07-10 08:34:02       44 阅读
  7. p1216数字三角形

    2024-07-10 08:34:02       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 08:34:02       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 08:34:02       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 08:34:02       90 阅读
  4. Python语言-面向对象

    2024-07-10 08:34:02       98 阅读

热门阅读

  1. Electron 简单搭建项目

    2024-07-10 08:34:02       35 阅读
  2. adb 常用的命令总结

    2024-07-10 08:34:02       30 阅读
  3. gcc: options: -specs

    2024-07-10 08:34:02       29 阅读
  4. Python题解Leetcode Hot 100之栈和堆

    2024-07-10 08:34:02       30 阅读
  5. docker容器如何与本地配置文件关联

    2024-07-10 08:34:02       37 阅读
  6. SQL 字段类型-上

    2024-07-10 08:34:02       35 阅读
  7. C++ 入门04:数组与字符串

    2024-07-10 08:34:02       24 阅读
  8. 简谈设计模式之原型模式

    2024-07-10 08:34:02       31 阅读
  9. GPT带我学-设计模式-13策略模式

    2024-07-10 08:34:02       29 阅读
  10. 写一个字符设备的驱动步骤

    2024-07-10 08:34:02       30 阅读
  11. Transformer和Bert的原理是什么

    2024-07-10 08:34:02       29 阅读