3274:【例45.3】 寻找最低数
[例45.3] 寻找最低数
C语言:
#include<stdlib.h>
#include<stdio.h>
int n;
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==0)
{
break;
}
printf("%d\n",(n&(-n)));
}
return 0;
}
C++代码:
/*
3274:【例45.3】 寻找最低数
http://bas.ssoier.cn:8086/problem_show.php?pid=3274
https://blog.csdn.net/xsjzn/article/details/104116707
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
ll quickPow(ll n,ll m){
ll res =1;
if(m==0){
return 1;
}else if(m%2==1){
return n*quickPow(n,m-1);
}else{
ll num=quickPow(n,m/2);
return num*num;
}
}
int main(){
int num;
while(scanf("%d",&num)!=EOF){
if(num==0){
break;
}
ll t=0;
while(!(num&1)){
t++;
num>>=1;
}
cout<<quickPow(2,t)<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
while(cin>>n)
{
if(n==0)
{
break;
}
cout<<(n&(-n))<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
while(cin>>n&&n!=0){
for(int i=0;;i++){
if(n%2==1){k=i;break;}
n/=2;
}
cout<<pow(2,k)<<endl;
}
return 0;
}
python3源码:
n=int(input())
while n!=0:
print(n&-n)
n=int(input())








信息学奥赛CSP-J(入门组)初赛辅导
【睿爸信奥】2022CSP-J初赛模拟试卷及讲评
信息学奥赛之初赛 第1轮 讲解(1-8课)
信息学奥赛之初赛 第1轮 讲解(01-08课)_第 1 页 共 116 页信息学奥赛之初赛 第 1 轮 讲解(1-8 课)-CSDN博客
CSP初赛(1-15课)
CSP-J初赛集训(0-26课)
2023csp-j&s初赛普及组
备战CSP2022, 初赛讲解, NOIP CSP-J CSP-S CSP-J/S
决战选择题 CSP-J 2022 选择题解析 初赛
信息学奥赛 链表专题

688

被折叠的 条评论
为什么被折叠?



