1094
막대기
- 생략
import java.util.Scanner;
public class bj1094_0124 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int X = sc.nextInt();
sc.close();
String binX = Integer.toBinaryString(X);
int res = 0;
for (int i = 0; i < binX.length(); i++)
if (binX.charAt(i) == '1')
res++;
System.out.println(res);
}
}
- 생략
1015
수열 정렬
- 생략
import java.util.Arrays;
import java.util.Scanner;
public class bj1015_0124 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] A = new int[N];
for (int i = 0; i < N; i++)
A[i] = sc.nextInt();
sc.close();
// A를 정렬한 B배열과, 결과가 입력될 P배열
int[] B = new int[N];
for (int i = 0; i < N; i++)
B[i] = A[i];
Arrays.sort(B);
int[] P = new int[N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] == B[j]) {
B[j] = 0;
P[i] = j;
break;
}
}
}
for (int i = 0; i < N; i++)
System.out.printf("%d ", P[i]);
}
}
- 생략
1057
토너먼트
- 생략
import java.util.Scanner;
public class bj1057_0124 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int A = sc.nextInt();
int B = sc.nextInt();
sc.close();
int cnt = 0;
while (N != 1) {
cnt++;
N = (int) Math.ceil((float) N / 2);
A = (A + 1) / 2;
B = (B + 1) / 2;
if (A == B)
break;
}
System.out.println(cnt);
}
}
- 생략
'PS - BOJ' 카테고리의 다른 글
1026, 1037, 1085 - 보물, 약수, 직사각형에서 탈출 (0) | 2022.01.26 |
---|---|
1003 - 피보나치 함수 (0) | 2022.01.25 |
1034 - 램프 (0) | 2022.01.24 |
1138 - 한 줄로 서기, 1032 - 명령 프롬프트 (0) | 2022.01.23 |
1124 - 언더프라임 (0) | 2022.01.23 |