题目链接
题目大意
题意是说把一个数转换成二进制,输出1的位置(下标从0开始算)。
解题思路
转个二进制,遍历一遍。
参考代码
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;
/** Constant List .. **/ //{
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
int s[10000001];
int main()
{
#ifdef DoubleQ
freopen("in.txt","r",stdin);
#endif
int d;
scanf("%d",&d);
while(d--)
{
int n;
scanf("%d",&n);
int t = 0;
int k;
while(n != 0)
{
k = n % 2;
s[t ++] = k;
n /= 2;
}
for(int i = 0; i < t ; i ++)
{
if(s[i] == 1)
printf("%d%c", i , i == t - 1 ? '\n' : ' ');
}
}
}
暂无评论