当前位置:网站首页>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;
}
边栏推荐
- 华为AppLinking中统一链接的创建和使用
- Binary tree topic -- p1030 [noip2001 popularization group] find the first order
- [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
- Implementation of six singleton modes
- 二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
- Jenkins安装
- What are the software product management systems? Inventory of 12 best product management tools
- 高德根据轨迹画线
- How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
- Jsp webshell Free from killing - The Foundation of JSP
猜你喜欢
QT learning diary 7 - qmainwindow
[AGC] build service 3 - authentication service example
华为AppLinking中统一链接的创建和使用
flink二開,實現了個 batch lookup join(附源碼)
How to implement tabbar title bar with list component
【深入浅出玩转FPGA学习5-----复位设计】
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)
【AGC】构建服务3-认证服务示例
[play with FPGA learning 5 in simple terms ----- reset design]
Uncover the secrets of Huawei application market application statistics
随机推荐
TIPC protocol
Matlab processing of distance measurement of experimental electron microscope
[play with FPGA learning 5 in simple terms ----- reset design]
PCL projection point cloud
php中self和static在方法中的区别
js中给数组添加元素的方法有哪些
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
III Chip startup and clock system
[ark UI] implementation of the startup page of harmonios ETS
Binary tree topic -- p1030 [noip2001 popularization group] find the first order
华为游戏初始化init失败,返回错误码907135000
K-d tree and octree of PCL
C#中索引器
2022-06-17
Resources读取2d纹理 转换为png格式
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
QT learning diary 7 - qmainwindow
JSP webshell free -- webshell free
Creation and use of unified links in Huawei applinking
TIPC Getting Started6