杭电Hdu 1390 Binary Numbers
2013-01-06 16:38
337 查看
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Hdu1390 {
static List<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int m = sc.nextInt();
binary(m);
boolean t = false;
for (int j = 0; j < list.size(); j++) {
if (list.get(j) == 1) {
if (t) {
System.out.print(" ");
}
System.out.print(j);
t = true;
}
}
System.out.println();
list.clear(); //注意每次要清空
}
}
static void binary(int x) {
int a = 0;
while (x != 0) {
a = x % 2;
x = x / 2;
list.add(a);
}
}
}
import java.util.List;
import java.util.Scanner;
public class Hdu1390 {
static List<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int m = sc.nextInt();
binary(m);
boolean t = false;
for (int j = 0; j < list.size(); j++) {
if (list.get(j) == 1) {
if (t) {
System.out.print(" ");
}
System.out.print(j);
t = true;
}
}
System.out.println();
list.clear(); //注意每次要清空
}
}
static void binary(int x) {
int a = 0;
while (x != 0) {
a = x % 2;
x = x / 2;
list.add(a);
}
}
}
相关文章推荐
- HDU 1390 Binary Numbers
- HDU1390_Binary Numbers【水题】【位运算】
- 杭电ACM1390——Binary Numbers
- HDU 1390 Binary Numbers
- HDU 1390 || ZOJ 1383 Binary Numbers
- hdu 1390 Binary Numbers
- HDU1390 ZOJ1383 Binary Numbers【水题+输入输出】
- HDU 1390 Binary Numbers
- 杭电 HDU ACM 1390 Binary Numbers
- Binary Numbers 1390 HDU
- HDU 1390 Binary Numbers(数学题)
- 杭电OJ题 1390 Binary Numbers解题报告
- hdu 1390 Binary Numbers
- hdu1390-Binary Numbers
- hdu 1390 Binary Numbers
- 【HDU】1390 Binary Numbers
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
- 杭电 HDU 1060 Leftmost Digit
- hdu杭电1002 Train Problem I【栈】
- 产生冠军 HDU杭电 2094【字符串处理】