题意:给一个数,转化为二进制后,反转后,去除前导零,在转化为十进制输出。
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5142
思路:模拟,将数转化二进制逐位存储在数组中,在逆向转化。
注意点:无
以下为AC代码:
Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
12492440 | 2014-12-13 22:48:23 | Accepted | 5142 | 0MS | 1200K | 1073 B | G++ | luminous11 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
int main()
{
int n;
int t;
int num[100];
cin >> t;
while ( t -- )
{
cin >> n;
int cnt = 1;
while ( n )
{
num[cnt++] = n % 2;
n /= 2;
}
int sum = 0;
int k = 1;
for ( int i = cnt - 1; i > 0; i --, k *= 2 )
{
sum += ( num[i] ) * k;
}
cout << sum << endl;
}
return 0;
}