#include<iostream>
using namespace std;
int num[105];
int ans[105];
void init()
{
int temp=2;
for(int i=0; i<30; i++)
{
num[i]=temp-1;
temp*=2; }
} int main()
{
int t,n;
cin>>t;
init();
while(t--)
{
cin>>n;
if(n==0)
{
cout<<"0 []"<<endl;
continue;;
}
cout<<n<<" [";
int ct=0;
for(int i=29; i>=0; i--)
{
while(n>=num[i])
{
n=n-num[i];
ans[++ct]=i;
if(n==0)
break;
}
} for(int i=ct;i>0; i--)
{
cout<<ans[i]; if(i!=0) cout<<",";
else cout<<"]"<<endl;
} }
}

  注意:while的使用 和++i i++

题意的理解

UVA2639的更多相关文章

随机推荐

  1. jquery的curCSS方法

    核心思想是用getComputedStyle获取样式,如果没有获取到就判断是不是动态创建的元素,如果是则用style获取行内样式.看重点(注释部分)代码吧! curCSS = function( el ...

  2. flex引起height:100%失效

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. One EEG preprocessing pipeline - EEG-fMRI paradigm

    The preprocessing pipeline of EEG data from EEG-fMRI paradigm differs from that of regular EEG data, ...

  4. Oracle 中的伪列

    昨天做了一个Oracle PL/SQL 相关的测试,其中有一道这样的题目:   下列那些是Oracle的伪列(ACD)  A.ROWID   B.ROW_NUMBER()  C.LEVEL  D.RO ...

  5. Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  6. Grumpy: Go 上运行 Python!

    Google 运行数百万行Python代码用于驱动youtube.com和YouTube API的前端服务器,每秒可以提供数百万的请求! YouTube的前端运行在CPython 2.7上,所以我们投 ...

  7. Codeforces Round #381(div 2)

    A.(分类讨论) 题意:你有n本书,有三种买书方案,花a元买1本,花b元买2本,花c元买3本,问最少花多少钱,使得你书的总数是4的倍数 分析:分类讨论的题,但是要注意你可以买超过4本书--可以买5本. ...

  8. js版弹力球实例

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>弹 ...

  9. python命令行下安装redis客户端

    1. 安装文件: https://pypi.python.org/pypi/setuptools 直接下载然后拷贝到python目录下同下面步骤 下载 ez_setup.py>>> ...

  10. 【OpenJudge 1665】完美覆盖

    http://noi.openjudge.cn/ch0405/1665/?lang=zh_CN 状压水题,手动转移 #include<cstdio> #include<cstring ...