본문 바로가기

Day 8: Dictionaries and Maps Task Given names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for is not found, print Not found instead.Note: Your phone book should be a Di.. 더보기
Day 7: Arrays Task Given an array, , of integers, print 's elements in reverse order as a single line of space-separated numbers.Input FormatThe first line contains an integer, (the size of our array). The second line contains space-separated integers describing array 's elements.Constraints, where is the integer in the array.Output FormatPrint the elements of array in reverse order as a single line of space-.. 더보기
Day 6: Let's Review Task Given a string, , of length that is indexed from to , print its even-indexed and odd-indexed characters as space-separated strings on a single line (see the Sample below for more detail).Note: is considered to be an even index.Input FormatThe first line contains an integer, (the number of test cases). Each line of the subsequent lines contain a String, .ConstraintsOutput FormatFor each Stri.. 더보기
Level 1 - 나누어 떨어지는 숫자 배열 divisible 메소드는 int형 배열 array와 int divisor를 매개변수로 받습니다. array의 각 element 중 divisor로 나누어 떨어지는 값만 포함하는 새로운 배열을 만들어서 반환하도록 divisible에 코드를 작성해 보세요.예를들어 array가 {5, 9, 7, 10}이고 divisor가 5이면 {5, 10}을 리턴해야 합니다. 풀이import java.util.Arrays; import java.util.ArrayList; import java.util.List; class Divisible { public int[] divisible(int[] array, int divisor) { //ret에 array에 포함된 정수중, divisor로 나누어 떨어지는 숫자를 순서대로.. 더보기
Level 1 - 문자열 내림차순으로 배치하기 reverseStr 메소드는 String형 변수 str을 매개변수로 입력받습니다. str에 나타나는 문자를 큰것부터 작은 순으로 정렬해 새로운 String을 리턴해주세요. str는 영문 대소문자로만 구성되어 있으며, 대문자는 소문자보다 작은 것으로 간주합니다. 예를들어 str이 Zbcdefg면 gfedcbZ을 리턴하면 됩니다. 풀이import java.util.Arrays; public class ReverseStr { public String reverseStr(String str){ char[] chars = str.toCharArray(); Arrays.sort(chars); return new StringBuffer(new String(chars)).reverse().toString(); } //.. 더보기
Level 1 - 피보나치 수 피보나치 수는 F(0) = 0, F(1) = 1일 때, 2 이상의 n에 대하여 F(n) = F(n-1) + F(n-2) 가 적용되는 점화식입니다. 2 이상의 n이 입력되었을 때, fibonacci 함수를 제작하여 n번째 피보나치 수를 반환해 주세요. 예를 들어 n = 3이라면 2를 반환해주면 됩니다. 풀이import java.util.LinkedList; class Fibonacci { public long fibonacci(int num) { if (num == 0 || num == 1) return num; else { LinkedList lists = new LinkedList(); lists.add(0L); lists.add(1L); for (int i = 2; i 더보기
Level 1 - 최대값과 최소값 getMinMaxString 메소드는 String형 변수 str을 매개변수로 입력받습니다. str에는 공백으로 구분된 숫자들이 저장되어 있습니다. str에 나타나는 숫자 중 최소값과 최대값을 찾아 이를 (최소값) (최대값)형태의 String을 반환하는 메소드를 완성하세요. 예를들어 str이 1 2 3 4라면 1 4를 리턴하고, -1 -2 -3 -4라면 -4 -1을 리턴하면 됩니다. 풀이import java.util.Arrays; public class GetMinMaxString { public String getMinMaxString(String str) { String [] strNumbers = str.split(" "); int[] numbers = new int[strNumbers.length].. 더보기
Level 1 - 수박수박수박수박수박수 water_melon함수는 정수 n을 매개변수로 입력받습니다. 길이가 n이고, 수박수박수...와 같은 패턴을 유지하는 문자열을 리턴하도록 함수를 완성하세요.예를들어 n이 4이면 '수박수박'을 리턴하고 3이라면 '수박수'를 리턴하면 됩니다. 풀이public class WaterMelon { public String watermelon(int n){ String result = ""; for(int i = 1; i 더보기
Level 1 - 가운데 글자 가져오기 getMiddle메소드는 하나의 단어를 입력 받습니다. 단어를 입력 받아서 가운데 글자를 반환하도록 getMiddle메소드를 만들어 보세요. 단어의 길이가 짝수일경우 가운데 두글자를 반환하면 됩니다. 예를들어 입력받은 단어가 power이라면 w를 반환하면 되고, 입력받은 단어가 test라면 es를 반환하면 됩니다. 풀이 class StringExercise{ String getMiddle(String word){ String result = ""; int middle = (word.length() / 2); if (word.length() % 2 == 0) { middle = (word.length() / 2); result += String.valueOf(word.charAt(middle - 1)); .. 더보기
Non-Repeating Character (Java) Implement a function that takes a string and returns the first character that does not appear twice or more.Example:"abacc" -> 'b' ('a' appears twice, and so does 'c')"xxyzx" -> 'y' ('y' and 'z' are non-repeating characters, and 'y' appears first)If there is no non-repeating character, return null. 풀이 import java.util.*; public class NR { public static void main(String[] args) { // NOTE: The fol.. 더보기