原题链接:Bitset
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28587 Accepted Submission(s): 21053 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 Author 8600 && xhd Source Recommend linle |
题记:
进制转换的水题,题中进制转换函数模板可以copy下来随时用~
C++程序如下:
#include <iostream>
using namespace std;
int convert(int n, int base){
int digit=0;
int power=1;
while(n){
digit += power * (n%base);
n /= base;
power *= 10;
}
return digit;
}
int main(void){
int num;
while(cin >> num)
cout << convert(num, 2) << endl;
return 0;
}