杭电ACM1390——Binary Numbers

这一题,输入的数转换成二进制,输出二进制位为1的位置。

下面的AC代码:

#include <iostream>
using namespace std;

int main()
{
	int count, a[100];
	int i, j, n;
	scanf("%d", &n);
	while(n--)
	{
		cin >> i;
		j = 0; count = 0;
		while(1)
		{
			if(i % 2)
				count++;
			a[j++] = i % 2;
			i /= 2;
			if(!i)
				break;
		}
		for(int k = 0; k < j; k++)
		{
			if(a[k])
			{
				count != 1 ? cout << k << ' ' : cout << k << endl;
				count--;
			}
		}
	}
	return 0;
}
时间: 2024-08-28 19:43:19

杭电ACM1390——Binary Numbers的相关文章

杭电 3711 Binary Number

passport.baidu.com/?business&un=%E5%92%8C%E9%9D%99%5F%E5%B0%8F%E5%A6%B9%5F%E6%89%BE#0 passport.baidu.com/?business&un=%E4%BC%8A%E5%AE%81%5F%E5%AD%A6%E5%A6%B9%5F%E6%89%BE#0 passport.baidu.com/?business&un=%E4%BC%8A%E5%AE%81%5F%E5%B0%8F%E5%A7%90

杭电 HDU ACM 1390 Binary Numbers

Binary Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3372    Accepted Submission(s): 2026 Problem Description Given a positive integer n, find the positions of all 1's in its binary r

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b

杭电 HDU ACM 2795 Billboard(线段树伪装版)

Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14144    Accepted Submission(s): 6058 Problem Description At the entrance to the university, there is a huge rectangular billboard of

杭电 1711 Number Sequence

Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10239    Accepted Submission(s): 4656 Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1],

杭电1078(记忆搜索)

一道记忆搜索题,记忆搜索题就是搜索的形式+DP的思想! 题目: FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmouse has hid