当前位置:网站首页>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;
}
边栏推荐
- 【深入浅出玩转FPGA学习3-----基本语法】
- Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
- 【深入浅出玩转FPGA学习4----漫谈状态机设计】
- Use of vscode tool
- 主键策略问题
- TIPC Getting Started6
- [paid promotion] collection of frequently asked questions, recommended list FAQ
- TIPC协议
- 洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
- 一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)
猜你喜欢
![[in simple terms, play with FPGA learning 3 ----- basic grammar]](/img/f0/0204fa5197033877dc0758203253ae.png)
[in simple terms, play with FPGA learning 3 ----- basic grammar]

JVM之垃圾回收器
![[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched](/img/5c/b0030fd5fbc07eb94013f2699c2a04.png)
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched

flink二開,實現了個 batch lookup join(附源碼)

华为游戏初始化init失败,返回错误码907135000

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises

二.Stm32f407芯片GPIO编程,寄存器操作,库函数操作和位段操作

Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)

2022爱分析· 国央企数字化厂商全景报告

QT learning diary 7 - qmainwindow
随机推荐
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
Oracle notes
洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
LVM操作
P1055 [noip2008 popularization group] ISBN number
【深入浅出玩转FPGA学习4----漫谈状态机设计】
[paid promotion] collection of frequently asked questions, recommended list FAQ
C# 文件与文件夹操作
js中给数组添加元素的方法有哪些
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
【AI应用】海康威视iVMS-4200软件安装
快应用中实现自定义抽屉组件
JVM之垃圾回收器
Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
实验电镜距离测量之Matlab处理
PCL projection point cloud
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
AppGallery Connect场景化开发实战—图片存储分享
Static variables in static function
洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)