当前位置:网站首页>Complement (Mathematical Simulation
Complement (Mathematical Simulation
2022-07-02 11:11:00 【lcxdz】
#include<bits/stdc++.h>
using namespace std;
void add(int a[],int b[],int c[],int cnt){
int u=0;
for(int i=0;i<=cnt;i++){
u+=a[i]+b[i];
c[i]=u%2;
u/=2;
}
}
int main(){
int T;
cin>>T;
while(T--){
int a[50]={
0},b[50]={
1,0},c[50];
int n,h=0;
cin>>n;
if(n>=0){
while(n){
a[h++]=n%2;
n/=2;
}
for(int i=31;i>=0;i--) cout<<a[i];
}
else {
n=-n;
while(n){
a[h++]=n%2;
n/=2;
}
for(int i=0;i<32;i++){
if(a[i]==0) a[i]=1;
else a[i]=0;
}
add(a,b,c,h-1);
// for(int i=31;i>=0;i--) cout<<a[i];
// cout<<" ";
for(int i=h-1;i>=0;i--) cout<<c[i];
for(int i=31;i>h-1;i--) cout<<1;
}
cout<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int T;
cin>>T;
while(T--){
int n;
cin>>n;
int ch[35]={
};
if(n<0)
for(int i=1;i<=32;i++)ch[i]=1;
// cout<<endl;
// for(int i=1;i<=32;i++)cout<<ch[i];
// cout<<endl;
int tot=32;
int p=abs(n);
while(p){
ch[tot]=p%2;
p/=2;
tot--;
}
if(n>=0){
for(int i=1;i<=32;i++)cout<<ch[i];
cout<<endl;
}
else {
int ok=0;
for(int i=32;i>tot;i--){
if(ok==1){
if(ch[i]==1)ch[i]=0;
else ch[i]=1;
}
if(ch[i]==1){
ok=1;
}
}
for(int i=1;i<=32;i++)cout<<ch[i];
cout<<endl;
}
}
return 0;
}
边栏推荐
- LabVIEW为什么浮点数会丢失精度
- 二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
- Overview of integrated learning
- Appgallery connect scenario development practice - image storage and sharing
- 二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)
- flink二開,實現了個 batch lookup join(附源碼)
- 二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
- PCL projection point cloud
- C#中索引器
- 【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
猜你喜欢

Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
![[play with FPGA learning 5 in simple terms ----- reset design]](/img/57/816a59787259dc32b52897c069e1a6.png)
[play with FPGA learning 5 in simple terms ----- reset design]

一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)

QT learning diary 7 - qmainwindow

Implement custom drawer component in quick application

二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)

三.芯片启动和时钟系统

【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?

I STM32 development environment, keil5/mdk5.14 installation tutorial (with download link)

TIPC messaging3
随机推荐
sqlite 修改列类型
二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
STM32单片机编程学习
Nodejs+express+mysql simple blog building
What are the software product management systems? Inventory of 12 best product management tools
Hdu1234 door opener and door closer (water question)
[AGC] build service 3 - authentication service example
static 函数中的静态变量
从.bag文件中读取并保存.jpg图片和.pcd点云
一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)
【深入浅出玩转FPGA学习5-----复位设计】
函数式接口和方法引用
QT学习日记8——资源文件添加
Jsp webshell Free from killing - The Foundation of JSP
首份中国企业敏捷实践白皮书发布| 附完整下载
PCL eigen introduction and simple use
全网显示 IP 归属地,是怎么实现的?
flink二開,實現了個 batch lookup join(附源碼)
二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
How to transfer event objects and user-defined parameters simultaneously in Huawei express applications