본문 바로가기

Day 13: Abstract Classes Task Given a Book class and a Solution class, write a MyBook class that does the following:Inherits from BookHas a parameterized constructor taking these parameters:string string int Implements the Book class' abstract display() method so it prints these lines:, a space, and then the current instance's ., a space, and then the current instance's ., a space, and then the current instance's .Note:.. 더보기
Queues: A Tale of Two Stacks A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed from the front and new elements to be added to the rear. This is called a First-In-First-Out(FIFO) data structure because the first element added to the queue (i.e., the one that has been waiting the longest) is always the first one to be removed.A basic queue .. 더보기
Level 2 - 최솟값 만들기 자연수로 이루어진 길이가 같은 수열 A,B가 있습니다. 최솟값 만들기는 A, B에서 각각 한 개의 숫자를 뽑아 두 수를 곱한 값을 누적하여 더합니다. 이러한 과정을 수열의 길이만큼 반복하여 최종적으로 누적된 값이 최소가 되도록 만드는 것이 목표입니다.예를 들어 A = [1, 2] , B = [3, 4] 라면A에서 1, B에서 4를 뽑아 곱하여 더합니다.A에서 2, B에서 3을 뽑아 곱하여 더합니다.수열의 길이만큼 반복하여 최솟값 10을 얻을 수 있으며, 이 10이 최솟값이 됩니다. 수열 A,B가 주어질 때, 최솟값을 반환해주는 getMinSum 함수를 완성하세요. 풀이 import java.util.*; class TryHelloWorld { public int getMinSum(int []A, int .. 더보기
Level 2 - 소수 찾기 numberOfPrime 메소드는 정수 n을 매개변수로 입력받습니다.1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환하도록 numberOfPrime 메소드를 만들어 보세요.소수는 1과 자기 자신으로만 나누어지는 수를 의미합니다. (1은 소수가 아닙니다.)10을 입력받았다면, 1부터 10 사이의 소수는 [2,3,5,7] 4개가 존재하므로 4를 반환 5를 입력받았다면, 1부터 5 사이의 소수는 [2,3,5] 3개가 존재하므로 3를 반환 풀이 class NumOfPrime { int numberOfPrime(int n) { int result = 0; // 함수를 완성하세요. for (int i = 2; i 더보기
Day 10: Binary Numbers Task Given a base- integer, , convert it to binary (base-). Then find and print the base- integer denoting the maximum number of consecutive 's in 's binary representation.Input FormatA single integer, .ConstraintsOutput FormatPrint a single base- integer denoting the maximum number of consecutive 's in the binary representation of .Sample Input 15 Sample Output 11 Sample Input 213 Sample Output.. 더보기
Day 9: Recursion Recursive Method for Calculating Factorial Task Write a factorial function that takes a positive integer, as a parameter and prints the result of ( factorial).Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of .Input FormatA single integer, (the argument to pass to factorial).ConstraintsYour submission must contain a recursi.. 더보기
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로 나누어 떨어지는 숫자를 순서대로.. 더보기