[백준] 12단계 문제 모음
·
Hi🖐️/Java
12 정렬 배열의 원소를 순서대로 나열하는 알고리즘 1 2750 수 정렬하기 시간 복잡도가 O(n²)인 정렬 알고리즘으로 풀 수 있습니다. 예를 들면 삽입 정렬, 거품 정렬 등이 있습니다. import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException{ BufferedReader bfr = new Buff..
[백준] 11단계 문제 모음
·
Hi🖐️/Java
11 브루트 포스 가장 간단한 알고리즘인, 모든 경우의 수를 검사하는 브루트 포스 알고리즘을 배워 봅시다. 1 2798 블랙잭 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int T = scan.nextInt(); int Max = scan.nextInt(); int n[] = new int [T]; for(int i = 0; i
[백준] 10단계 문제 모음
·
Hi🖐️/Java
10단계. 재귀 재귀함수를 다뤄 봅시다. 1 10872 팩토리얼 재귀함수를 만들어서 제출해야한다. import java.util.Scanner; public class Main { static int factory = 1; public static int fac(int num) { if(num ==0) return factory; else{ factory *= num; return fac(num-1); } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(); fac(x); System.out.println(factory); } } 2 10870 피보나치 수 5 이 문제 ..
[백준] 9단계 문제 모음
·
Hi🖐️/Java
1 1978 소수 찾기 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); int count = 0; for(int t = 0; t
[백준] 8단계 문제 모음
·
Hi🖐️/Java
1 1712 손익분기점 처음에는 아래와 같이 작성하여 시간초과가 일어났다. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long A = scan.nextInt(); long B = scan.nextInt(); long C = scan.nextInt(); scan.close(); long count = 1; while(true) { if(B>=C) { System.out.println(-1); break;} if(A + B*count >= C*count) { count++; continue; } if(A + B*count < C..
[백준] 7단계 문제 모음
·
Hi🖐️/Java
1 11654 아스키 코드 public class Main { public static void main(String[] args) throws Exception{ int a = System.in.read(); System.out.println(a); } } 2 11720 숫자의 합 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int a[] = new int[scan.nextInt()]; int sum = 0; String x = scan.next(); for(in..
[백준] 6단계 문제 모음
·
Hi🖐️/Java
1 15596 정수 N개의 합 public class Test { long sum(int[] a) { long ans = 0; for(int i=0; i
[백준]5단계 문제 모음
·
Hi🖐️/Java
1 10818 최소, 최대 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int T = scan.nextInt(); int a[] = new int[T]; for(int i=0; i
[HackerRank] Solve Java
·
Hi🖐️/Java
2. Java If-Else import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int N = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); if (N%2 != 0) {Sys..
[백준]4단계 문제 모음
·
Hi🖐️/Java
제목에 링크를 입력하면 해당 문제로 이동합니다. 1 10952 A+B - 5 Java 0 0이 들어올 때까지 A+B를 출력하는 문제 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException{ BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.out)); int A =1; int B =1; while(true) { StringTokenizer st = ..
Liky
'Hi🖐️/Java' 카테고리의 글 목록