EOJ2581. 0 and 1

单点时限: 2.0 sec

内存限制: 256 MB

As we all kown,in computer’s world,the language is represented by ‘0’s and 1’s.The problem is coming,partychen want to know how many ‘0’s and ‘1’in a number based on binary if he give you a number based on decimal.

输入格式

The first line of input gives the number of cases, N(1⩽N⩽100). N test cases follow.

The next N lines will each contain a integers M(1⩽M⩽10000000) based on decimal, as described above.

输出格式

For each test case, output two numbers in one line separately represent the sum of ‘0’s and ‘1’s.

Hint:

If give you a 10 base on decimal,you get 1010 base on binary,and there are two ‘0’s and two ‘1’s.So you must output 2 2.

样例

input

2
10
11

output

2 2
1 3

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n;
    int temp;
    int count = 0;
    cin >> n;
    
    vector<int> vints;
    for(int i=0;i<n;i++){
		cin	>> temp;
		vints.insert(vints.end(), temp);
	}

	int sum0=0, sum1=0;	
    for(int i=0;i<n;i++){
    	while(vints[i] > 0)
    	{
        	if(vints[i]%2 == 1)
           		sum1++;
           	else	
           		sum0++;
        	vints[i] = vints[i] >> 1;
    	}
    	cout << sum0 <<" "<<  sum1 << endl;
    	sum1=0; 
    	sum0=0;
	}

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值