hdu 2051 Bitset(进制转换)

Problem 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
解:和hdu 2031 是一个题,代码直接拿过来用一下。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

const double inf=1e20;
const int maxn=2e5+10;
const int mod=1e9+7;

int n,m;

void f(int x){
    if(x/m!=0){
        f(x/m);
    }
    int xx=x%m;
    if(xx<10)
        printf("%d",xx);
    else if(xx>=10)printf("%c",xx-10+'A');
}

int main(){
    m=2;
    while(scanf("%d",&n)!=EOF){
        if(n<0){
            printf("-");
            n=-n;
        }
        f(n);
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/wz-archer/p/12450816.html