문제설명 소스코드 import java.util.Stack; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Stack stack = new Stack(); //스택 생성 int K = sc.nextInt(); for(int i = 0; i < K; i++) { int input = sc.nextInt(); if(input == 0) stack.pop(); //0이면 팝 else stack.push(input); //0이 아니면 푸시 } int sum = 0; for(int i = 0; i < stack.size(); ++i) { s..
문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); System.out.print(factorial(N) / (factorial(N-K)*factorial(K))); } static int factorial(int n) { long count = 1; if(n == 0) return (int)count; else { for(int i = 1; i
문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long count = 1; if (N==0) System.out.print(1); else { for(int i = 1; i
문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); System.out.print((int)Math.pow(2, N)); } } 설명 한 층을 내려올 때마다 경우의 수는 2가지 이므로 N층을 내려올 때 경우의 수는 2^N개 이다.
문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); System.out.print(N * (N - 1)); } } 설명 생략
문제설명 소스코드 import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int arr[] = new int[N]; //가로수의 개수 입력 받음 int minDivisor = 0; int sum = 0; for(int i = 0; i < N; ++i) arr[i] = Integer.parseInt(br.read..
문제설명 소스코드 import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); HashMap m = new HashMap(); for (int i = 0; i < N; i++) { String name = sc.next(); String log = sc.next(); if (m.containsKey(name)) m.remove(name); //최초 입력이 아니..
문제설명 소스코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int..