Binary Watch_太阁竞赛A

题目1 : Binary Watch
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary digits to display minutes (00 - 59).

For example 11:26 is displayed as 01011:011010.  

Given a number x, output all times in human-readable format "hh:mm" when exactly x digits are 1.  


输入
An integer x. (0 ≤ x ≤ 9)  

输出
All times in increasing order.  

样例输入
1
样例输出
00:01  
00:02  
00:04  
00:08  
00:16  
00:32  
01:00  
02:00  
04:00  
08:00  

16:00


【我的程序】

#include <iostream>
using namespace std;

int compt(int x)
{
    int ans=0;
    while (x>0){ if (x%2==1) ans++; x/=2; }
    return ans;
}

int main()
{
    int n,a[60];
    cin>>n;
    for (int i=0;i<=59;i++) a[i]=compt(i);
    for (int i=0;i<=23;i++)
        for (int j=0;j<=59;j++)
            if (a[i]+a[j]==n) cout<<i/10 <<i%10 <<':' <<j/10 <<j%10 <<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值