반응형 전체 글96 백준알고리즘:p2447 별찍기 10 분류: 재귀 ▶문제 ▶코드 //백준알고리즘 제출시 클래스 이름은 Main으로 바꿔야 됨 package recursion; import java.io.IOException; import java.util.Arrays; import java.util.Scanner; //진심 너무 어렵다 public class p2447 { /* *** * * *** */static char[][] array; public static void main(String args[]) throws IOException{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); array = new char[N][N]; for(int i=0; i 2021. 3. 28. 백준알고리즘:p10870 피보나치 수 5 분류: 재귀 ▶문제 ▶코드 //백준알고리즘 제출시 클래스 이름은 Main으로 바꿔야 됨 package recursion; import java.util.Scanner; public class p10870_fibo { //피보나치 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int answer = fibonacci(n); System.out.print(answer); sc.close(); } public static int fibonacci(int x) { if(x==0) return 0; else if(x==1) return 1; else return fibonacci(x.. 2021. 3. 28. 백준알고리즘:p10872 팩토리얼 [재귀] 분류: 재귀 ▶문제 ▶코드 //백준알고리즘 제출시 클래스 이름은 Main으로 바꿔야 됨 package recursion; import java.util.Scanner; //재귀 public class p10872 { //팩토리얼 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int answer = factorial(n); System.out.print(answer); sc.close(); } public static int factorial(int x) { if(x 2021. 3. 28. 백준알고리즘:p2292 벌집 분류: 기본수학1 ▶문제 ▶코드 //백준알고리즘 제출시 클래스 이름은 Main으로 바꿔야 됨 package math_1; import java.util.Scanner; public class p2292 { //벌집 1+1 ~ 1+1*6 / 7+1 ~ 7+2*6 / first(=start+1) ~ start+x*6 //중요: 답은 x+1해줘야됨. x는 지나간 문의 갯수, x+1은 지나간 방의 갯수(문제는 방의 갯수를 세는 것이다.) //13->2개의 문을 지나고 3개의 방을 지난다. public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x =1, start=1; int ans.. 2021. 3. 28. 백준알고리즘:p1011 Fly me to the Alpha Centauri 분류: 기본 수학1 ▶문제 ▶코드 //백준알고리즘 제출시 클래스 이름은 Main으로 바꿔야 됨 package math_1; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class p1011 { //d거리 이동 횟수= (루트 거리)*2-1 를 올림한 값. public static void main(String[] args) { try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new .. 2021. 3. 28. 백준알고리즘:p1978, p2581 소수찾기 소수 분류: 기본수학2 ▶문제 ▶코드 //백준알고리즘 제출시 클래스 이름은 Main으로 바꿔야 됨 package math_2; import java.util.Scanner; public class p1978 { //소수찾기 public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count =0; for(int i=0; i 방법2: 2~루트n까지 나누기 n=7 일때, 1과 2의 제곱은 1, 4로 나누어 볼 가치가 있지만 3은 3^2=9 이므로 나누어 볼 가치가 없다. 그래서 루트n까지 나누는 것.. ※1은 소수가 아니다... 2021. 3. 28. 이전 1 ··· 8 9 10 11 12 13 14 ··· 16 다음 반응형