1.영화감독 숌
import java.util.Scanner;
public class movie {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int rank = input.nextInt();
int count = 1;
int output =666;
while(count != rank){
output++;
if(String.valueOf(output).contains("666"))
count++;
}
System.out.println(output);
}
}
2.랜선 자르기
import java.util.Arrays;
import java.util.Scanner;
public class cutcut {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int have = sc.nextInt();
int need = sc.nextInt();
int[] length = new int[have];
for(int i = 0; i < have; i++){
length[i] = sc.nextInt();
}
Arrays.sort(length);
long max=length[length.length-1];
long min=1;
long mid=0;
max++;
while(min<max){
mid = (max+min)/2;
long count = 0;
for(int j = 0; j < length.length; j++){
count += (length[j]/mid);
}
if (count < need) {
max = mid;
}else{
min = mid + 1;
}
}
System.out.println(min-1);
}
}
3.스택수열
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class stack {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
Queue<Integer> queue = new LinkedList<>();
Stack<Integer> stk = new Stack<>();
for (int i = 0; i < N; i++) {
queue.add(Integer.parseInt(br.readLine()));
}
int n = 0;
int cnt = 0;
while (cnt != N) {
stk.push(++n);
sb.append("+").append("\n");
while (!stk.isEmpty() && stk.peek().intValue() == queue.peek().intValue()) {
stk.pop();
queue.poll();
sb.append("-").append("\n");
cnt++;
}
if ((!stk.isEmpty()) && stk.peek().intValue() > queue.peek().intValue()) {
break;
}
}
if (!stk.isEmpty()) {
System.out.println("NO");
return;
}
System.out.println(sb);
}
}
4.수찾기
import java.util.Scanner;
import java.util.stream.IntStream;
public class find_num {
public static int[] isThereNum(int[] firstArray,int[] secondArray){
int[] newArray = new int[secondArray.length];
for(int k = 0; k < secondArray.length; k++){
int check = secondArray[k];
if(IntStream.of(firstArray).anyMatch(a -> a == check)) {
newArray[k] = 1;
}else{
newArray[k] = 0;
}
}
return newArray;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int firstArrayLength = sc.nextInt();
int[] firstArray = new int[firstArrayLength];
for(int i = 0 ; i < firstArrayLength; i++){
firstArray[i] = sc.nextInt();
}
int secondArrayLength = sc.nextInt();
int[] secondArray = new int[secondArrayLength];
for(int j = 0; j < secondArrayLength; j++){
secondArray[j] = sc.nextInt();
}
int[] returnArray = isThereNum(firstArray,secondArray);
for (int o = 0; o < secondArray.length; o++){
System.out.println(returnArray[o]);
}
}
}
'지-코바' 카테고리의 다른 글
[지코바]3회차 4번문제 풀이 (0) | 2022.02.10 |
---|---|
[지코바] 3회차 문제풀이 (0) | 2022.02.03 |
[지코바] 12/10 문제풀이 (0) | 2021.12.10 |
[지코바]5회차 문제풀이 - 상속 (0) | 2021.11.25 |
4회차 문제풀이 - 논리연산자 (0) | 2021.10.28 |