diff --git a/algorithm/.idea/misc.xml b/algorithm/.idea/misc.xml index cf9abe6..b95853c 100644 --- a/algorithm/.idea/misc.xml +++ b/algorithm/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/algorithm/src/BJ1009.java b/algorithm/src/BJ1009.java new file mode 100644 index 0000000..9c4dbdf --- /dev/null +++ b/algorithm/src/BJ1009.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +public class BJ1009 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int t = in.nextInt(); //반복 횟수 + int a, b, c; + + for(int i = 0; i < t; i++) { + a = in.nextInt(); + b = in.nextInt(); + c = 1; + + for(int j = 0; j < b; j++){ + c = (c * a) % 10; + if (c == 0) + c = 10; + } + System.out.println(c); + } + } +} diff --git a/algorithm/src/BJ1212.java b/algorithm/src/BJ1212.java new file mode 100644 index 0000000..7f46cb8 --- /dev/null +++ b/algorithm/src/BJ1212.java @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class BJ1212 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String a = in.nextLine(); + StringBuilder b = new StringBuilder(); +//객체를 생성하는 것이 아니라 기존의 데이터에 더하는 방식을 사용하여 속도가 빠르다고 한다. + for (int i = 0; i < a.length(); i++){ //입력된 값의 크기만큼 반복 + char c = a.charAt(i); //a의 i번째 글자에 차례에 순서대로 갑니다. + switch (c) { // b.append(3 "011", 1 "001", 4 "100") 더해줌 + case '0': b.append("000"); break; + case '1': b.append("001"); break; + case '2': b.append("010"); break; + case '3': b.append("011"); break; + case '4': b.append("100"); break; + case '5': b.append("101"); break; + case '6': b.append("110"); break; + case '7': b.append("111"); break; + default: break; + } + } + if (b.charAt(0)=='0') b.deleteCharAt(0); + if (b.charAt(0)=='0') b.deleteCharAt(0); + System.out.println(b); + } +} diff --git a/algorithm/src/BJ1373.java b/algorithm/src/BJ1373.java new file mode 100644 index 0000000..fb628e1 --- /dev/null +++ b/algorithm/src/BJ1373.java @@ -0,0 +1,29 @@ +import java.util.Scanner; +public class BJ1373 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String a = in.nextLine(); + int size = a.length(); + if(size%3==1) + a = "00" + a; + if(size%3==2) + a = "0" + a; + + StringBuilder b = new StringBuilder(); + + int q = 0; + int w = 0; + int e; + + for (int i = 0; i <= a.length()-1; i++){ + int num = a.charAt(i)-'0'; + if(i%3==0) q = num*4; + else if(i%3==1) w = num*2; + else { + e = num; + b.append(q+w+e); + } + } + System.out.println(b); + } +} \ No newline at end of file diff --git a/algorithm/src/BJ1789.java b/algorithm/src/BJ1789.java new file mode 100644 index 0000000..3379492 --- /dev/null +++ b/algorithm/src/BJ1789.java @@ -0,0 +1,18 @@ +import java.util.Scanner; + +public class BJ1789 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + long a = in.nextLong(); + //자바 int는 21억정도까지 밖에 안됨 + //그러나 문제는 42억까지 요구함 + long sum = 0; + int count = 0; + for(int i = 1; ; i++) { + if(sum > a) break; + count++; + sum += i; + } + System.out.println(count-1); + } +} diff --git a/algorithm/src/BJ1934.java b/algorithm/src/BJ1934.java new file mode 100644 index 0000000..3c4725f --- /dev/null +++ b/algorithm/src/BJ1934.java @@ -0,0 +1,21 @@ +import java.util.Scanner; + +public class BJ1934 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int t = in.nextInt(); + int d = 0; + for (int i = 0; i < t; i++) { + int a = in.nextInt(); + int b = in.nextInt(); + d = a * b; + int c; + while (b != 0) { + c = a % b; + a = b; + b = c; + } + System.out.println(d/a); + } + } +} diff --git a/algorithm/src/BJ1978.java b/algorithm/src/BJ1978.java new file mode 100644 index 0000000..5c5831f --- /dev/null +++ b/algorithm/src/BJ1978.java @@ -0,0 +1,21 @@ +import java.util.Scanner; +public class BJ1978 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int N = in.nextInt(); + int[] a = new int[N]; + int sum = 0; + for (int i = 0; i < a.length; i++) { + a[i] = in.nextInt(); + for(int j = 2; j <= a[i]; j++) { + if(j == a[i]){ + sum++; + } + if (a[i] % j == 0) { + break; + } + } + } + System.out.println(sum); + } +} \ No newline at end of file diff --git a/algorithm/src/BJ2839.java b/algorithm/src/BJ2839.java new file mode 100644 index 0000000..8850e1f --- /dev/null +++ b/algorithm/src/BJ2839.java @@ -0,0 +1,20 @@ +import java.util.Scanner; + +public class BJ2839 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int N = in.nextInt(); + int sum = 0; + while(true) { + if(N % 5 == 0) { + System.out.println(N / 5 + sum); + break; + } else if (N < 0){ + System.out.println(-1); + break; + } + N = N - 3; + sum++; + } + } +} diff --git a/algorithm/src/BJ2921.java b/algorithm/src/BJ2921.java new file mode 100644 index 0000000..fb5d645 --- /dev/null +++ b/algorithm/src/BJ2921.java @@ -0,0 +1,18 @@ +import java.util.Scanner; +public class BJ2921 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int N = in.nextInt(); + int a = 3; + int b = 6; + int m = 0; + int sum = 0; + for (int i = 0; i < N; i++) { + m = a; + sum += m; + a += b; + b += 3; + } + System.out.println(sum); + } +}