본문 바로가기

알고리즘

[Baekjoon] 10430번 / 나머지 문제 (A+B)%C는 ((A%C) + (B%C))%C 와 같을까? (A×B)%C는 ((A%C) × (B%C))%C 와 같을까? 세 수 A, B, C가 주어졌을 때, 위의 네 가지 값을 구하는 프로그램을 작성하시오. 입력 첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000) 출력 첫째 줄에 (A+B)%C, 둘째 줄에 ((A%C) + (B%C))%C, 셋째 줄에 (A×B)%C, 넷째 줄에 ((A%C) × (B%C))%C를 출력한다. 예제 입력1 5 8 4 예제 출력1 1 1 0 0 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(Syst.. 더보기
[Hackerrank] Operators Objective In this challenge, you will work with arithmetic operators. Check out the Turtorial tab for learning materials and an instructional video. Task Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost. Round the res.. 더보기
[Hackerrank] Data Types Objective Today, we're discussing data types. check out the Tutorial tab for learning materials and an instructional video! Task Complete the code in the editor below. The variables i, d, and s are already declared and initalized for you. You must: 1. Declare 3 variables: one of type int, one of type double, and one of type String. 2. Read 3 lines of input from stdin (according to the sequence g.. 더보기
[Hackerrank] Picking Numbers Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to 1. Example a = [1,1,2,2,4,4,5,5,5] There are two subarrays meeting the criterion: [1,1,2,2] and [4,4,5,5,5]. The maximum length subarray has 5 elements. Function Description Complete the pickingNumbers function in the editor below. pickingNumbers has the following.. 더보기
[Hackerrank] Forming a Magic Square We define a magic square to be an n x n matrix of distinct positive integers from 1 to n2 where the sum of any row, column, or diagonal of length n is always equal to the same number: the magic constant. You will be gicen a 3 x 3 matrix s of integers in the inclusive range [1,9]. We can convert any digit a to any other digit b in the range [1,9] at cost of |a-b|. Given s, convert it into a magic.. 더보기
[Hackerrank] Java Loops 1 Objective In this challenge, we're going to use loops to help us do some simple math. Task Given an integer, N, rint its first 10 multiples. Each mutiple N x i(where 1 더보기
[Hackerrank] Java Output Formatting java's System.out.printf function can be used to print formatted output. The purpose of this exercise is to test your understanding of formatting output using printf. To get you started, a portion of the solusion is provided for you in the editor; you must format and print the input to complete the solution. Input Format Every line of input will contain a String followed by an integer. Each Stri.. 더보기
[LeetCode] Running Sum of 1d Array class Solution { public int[] runningSum(int[] nums) { int[] answer = new int[nums.length]; int sum = 0; for(int i=0; i 더보기