ZOJ 2417 Lowest Bit

来源:互联网 发布:行政区域数据 编辑:程序博客网 时间:2024/05/29 11:57

查看原题

大意

给出数n,转换成二进制,从尾开始到第一个1为止的二进制部分转换为十进制。

思路

没啥好说的,尽量精简代码

代码

#include<iostream>#include<math.h>using namespace std;int main(){    int n;    while(cin>>n&&n!=0){        int s[8],temp=0,sum=0;        while(n){            s[temp++]=n%2;            n=n/2;            if(s[temp-1]==1){                sum+=pow(2,temp-1);                cout<<sum<<endl;                break;            }        }    }    return 0;}
0 0
原创粉丝点击