W - Bitset(第二季水)

Description

Give you a number on base ten,you should output it on base two.(0 < n < 1000)

Input

For each case there is a postive number n on base ten, end of file.

Output

For each case output a number on base two.

Sample Input

1 2 3

Sample Output

1 10 11

很简单  十进制化为二进制

题目中未提到小数 但应该考虑到

#include<iostream>
using namespace std;
void f(double n)
{
    int i,j,k,a[100],p=0;
    double t;
    k=n;
    t=n-k;
    if(k==0)cout<<0;
    while(k){
        if(k%2==0)a[p++]=0;
        else a[p++]=1;
        k=k/2;
    }
    for(i=p-1;i>=0;i--)cout<<a[i];
    if(t){
        cout<<".";
        while(1){
            t*=2;
            if(t>=1){
                cout<<1;
                if(t==1)break;
                else t-=1;
            }
            else cout<<0;
        }
    }
    cout<<endl;
}
int main()
{
    double n;
    while(cin>>n){
        f(n);
    }
    //system("pause");
    return 0;
}
时间: 2024-12-28 11:25:53

W - Bitset(第二季水)的相关文章

F - The Fun Number System(第二季水)

Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any position i (0 ≤ i < k-1) is 2^i. For example, a 3 bit

D - Counterfeit Dollar(第二季水)

Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coi

I - Long Distance Racing(第二季水)

Description Bessie is training for her next race by running on a path that includes hills so that she will be prepared for any terrain. She has planned a straight path and wants to run as far as she can -- but she must be back to the farm within M se

S - 骨牌铺方格(第二季水)

Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:         Input 输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50). Output 对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行. Sample Input 1 3 2 Sample Output 1 3 2 水题,同上一道小蜜

N - Robot Motion(第二季水)

Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N north (up the page)         S south (down the page)     

V - 不容易系列之(4)――考新郎(第二季水)

Description 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:         首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排;         然后,让各位新郎寻找自己的新娘.每人只准找一个,并且不允许多人找一个.         最后,揭开盖头,如果找错了对象就要当众跪搓衣板...         看来做新郎也不是容易的事情...         假设一共有

J - A + B Problem II(第二季水)

Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, eac

A - 高精度(大数)N次方(第二季水)

Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.         This problem requires that yo

P - A + B(第二季水)

Description 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. Input 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. Output 对每个测试用例输出1行,即A+B的值. Sample Input one + two = three four + five six = zero seven + eight nine