본문 바로가기

전체 글262

[알고리즘 문제] 문자열 압축 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next().toUpperCase(); String[] ary; int gap = 0; StringBuffer buffer = new StringBuffer(s); for (int i = 1; i "/"를 입력해 구분해줌 buffer.insert(i + gap, '/'); gap++; // 알파벳을 구분할 때마다 "/"을.. 2019. 4. 15.
[알고리즘 문제] Palindrome import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); char[] ary = s.toCharArray(); int mid; // 문자에서 가운데 값 조사 if (ary.length % 2 == 0) { // 글자의 긹이가 짝수인 경우 mid = ary.length / 2 - 1; for (int i = 0; i mid 2019. 4. 15.
[알고리즘 문제] Streetree import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int first,last; int GCD; int[] ary = new int[n]; int[] gap = new int[100000]; for(int i=0;i0){ gap[i-1]=ary[i]-ary[i-1]; } } for (int j = 1; j 2019. 4. 11.
[알고리즘 문제] pfactorization import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); while (num > 1) { // 나누는 대상의 값이 1이면 모두 나누어 떨어졌음을 의미하기 때문에 1보다 커야함 for (int i = 2; i 2019. 4. 9.
[알고리즘 문제] Fraction Sum import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); // 첫번째 수의 분자/분모 int aNume = sc.nextInt(); int aDeno = sc.nextInt(); // 두번쨰 수의 분자/분모 int bNume = sc.nextInt(); int bDeno = sc.nextInt(); // 두 수를 더한 값 int resultNume,resultDeno; resultDeno = aDeno*bDeno; resultNume=(aNume*bDeno)+(bNume*aDeno); // 결과값의 분자/분모에서 최대공약수를 구하기 위한 변수 i.. 2019. 4. 8.
[알고리즘 문제] import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // 테이블의 크기 int[][] ary = new int[n + 1][n + 1]; // 테이블을 표현할 배열 int[] A = new int[n + 1]; // A수열을 저장 할 배열 int a3; // A[3]값 for (int i = 1; i 2019. 4. 8.
[알고리즘 문제] attackRange import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt() - 1; // 행렬 크기 int y = sc.nextInt() - 1; // 행크기 int x = sc.nextInt() - 1; // 열 크기 int length = sc.nextInt(); // 범위 int ax, bx, cx, dx; int ay, by, cy, dy; int aax, bbx, ccx, ddx; int aay, bby, ccy, ddy; int count = 1; int[][] ary = new int[n + 1][n + 1];.. 2019. 4. 8.
[알고리즘 문제] Prosjek import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; // 일반 정수배열 int[] b = new int[n]; // a배열의 n번까지의 합을 n으로 나눈 값을 저장할 배열 int sum; // a배열에서 n번째까지의 합 for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } a[0] = b[0]; // a[0]은 a[0]까지의 값은 한번 나눈 값이므로 초기화 해줌 sum = a[0]; // sum 또한 a[0]을 제외하고.. 2019. 4. 6.
[알고리즌 문제] BeeHive import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 1) { // 첫번째 방이면 하나의 방을 지나왔으므로 1개를 출력하고 return; System.out.println(1); return; } int i = 1; while (true) { if (n >= (3 * i * i) - (3 * i) + 2 && n 2->9->21->20->38으로 가는 방법과 1->7->19->2->38으로 가는 방법이 있다. 전자는 총 5개의 방을 거쳐가지만, 후자는 총 4개의 방을 거쳐간다. 아이디.. 2019. 4. 6.