UVA2639


#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的更多相关文章
随机推荐
- jquery的curCSS方法
核心思想是用getComputedStyle获取样式,如果没有获取到就判断是不是动态创建的元素,如果是则用style获取行内样式.看重点(注释部分)代码吧! curCSS = function( el ...
- flex引起height:100%失效
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- One EEG preprocessing pipeline - EEG-fMRI paradigm
The preprocessing pipeline of EEG data from EEG-fMRI paradigm differs from that of regular EEG data, ...
- Oracle 中的伪列
昨天做了一个Oracle PL/SQL 相关的测试,其中有一道这样的题目: 下列那些是Oracle的伪列(ACD) A.ROWID B.ROW_NUMBER() C.LEVEL D.RO ...
- Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- Grumpy: Go 上运行 Python!
Google 运行数百万行Python代码用于驱动youtube.com和YouTube API的前端服务器,每秒可以提供数百万的请求! YouTube的前端运行在CPython 2.7上,所以我们投 ...
- Codeforces Round #381(div 2)
A.(分类讨论) 题意:你有n本书,有三种买书方案,花a元买1本,花b元买2本,花c元买3本,问最少花多少钱,使得你书的总数是4的倍数 分析:分类讨论的题,但是要注意你可以买超过4本书--可以买5本. ...
- js版弹力球实例
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>弹 ...
- python命令行下安装redis客户端
1. 安装文件: https://pypi.python.org/pypi/setuptools 直接下载然后拷贝到python目录下同下面步骤 下载 ez_setup.py>>> ...
- 【OpenJudge 1665】完美覆盖
http://noi.openjudge.cn/ch0405/1665/?lang=zh_CN 状压水题,手动转移 #include<cstdio> #include<cstring ...