자바 기본

    [백준/10799번] 쇠막대기(Stack)[Java]

    [백준/10799번] 쇠막대기(Stack)[Java]

    문제 여러 개의 쇠막대기를 레이저로 절단하려고 한다. 효율적인 작업을 위해서 쇠막대기를 아래에서 위로 겹쳐 놓고, 레이저를 위에서 수직으로 발사하여 쇠막대기들을 자른다. 쇠막대기와 레이저의 배치는 다음 조건을 만족한다. 쇠막대기는 자신보다 긴 쇠막대기 위에만 놓일 수 있다. - 쇠막대기를 다른 쇠막대기 위에 놓는 경우 완전히 포함되도록 놓되, 끝점은 겹치지 않도록 놓는다. 각 쇠막대기를 자르는 레이저는 적어도 하나 존재한다. 레이저는 어떤 쇠막대기의 양 끝점과도 겹치지 않는다. 아래 그림은 위 조건을 만족하는 예를 보여준다. 수평으로 그려진 굵은 실선은 쇠막대기이고, 점은 레이저의 위치, 수직으로 그려진 점선 화살표는 레이저의 발사 방향이다. 이러한 레이저와 쇠막대기의 배치는 다음과 같이 괄호를 이용하여..

    [백준/17248번] 물리 공부 [2019 전북대학교 프로그래밍 경진대회]

    [백준/17248번] 물리 공부 [2019 전북대학교 프로그래밍 경진대회]

    문제 전북대학교 컴퓨터공학부 신입생인 시현이는 공대 필수 교양인 기초물리를 수강중이다. 공부를 열심히 하는 시현이는 물리 문제집를 풀다가 다음과 같은 문제를 만났다. 평소 물리를 좋아하던 시현이는 ㄱ, ㄴ번은 단숨에 알았지만, ㄷ번을 풀 수 없어 절망에 빠져 있다. 절망에 빠져있는 시현이를 도와주도록 하자. 입력 첫째 줄에 테스트케이스 T를 입력한다. (1 ≤ T ≤ 100) 다음 줄부터 각 테스트케이스마다 자동차 A와 자동차 B의 속력 X, Y, 그리고 자동차 A의 가속도 Z가 주어진다. (각각의 입력은 띄어쓰기로 구분한다.) 단, 0 ≤ X < Y ≤ 10,000이고, 0

    042 - Method Header Practice 7

    042 - Method Header Practice 7

    Write a method header on line two with the following specs: Returns: a char Name: getChar Parameters: a String called "word" an integer called "index" Then, starting on line 4, write code that will return the character in "word" at the index "index" Examples: getChar("hello",1) ==> 'e' 1 2 3 4 5 6 7 8 9 10 11 12 import java.util.*; class Main { public static char getChar(String word, int index) ..

    041 - Method Header Practice 6

    041 - Method Header Practice 6

    Write a method header on line two with the following specs: Returns: a boolean Name: bothEven Parameters: an integer called "num1" an integer called "num2" Then, starting on line 4, write code that will return true if both num1 and num2 are even. Return false otherwise. Examples: bothEven(4,6) ==> true bothEven(3,4) ==> false bothEven(-1,1) ==> false 1 2 3 4 5 6 7 8 9 10 11 12 13 import java.uti..

    [백준/2525번] 오븐 시계(한국정보올림피아드)[Java]

    [백준/2525번] 오븐 시계(한국정보올림피아드)[Java]

    문제 KOI 전자에서는 건강에 좋고 맛있는 훈제오리구이 요리를 간편하게 만드는 인공지능 오븐을 개발하려고 한다. 인공지능 오븐을 사용하는 방법은 적당한 양의 오리 훈제 재료를 인공지능 오븐에 넣으면 된다. 그러면 인공지능 오븐은 오븐구이가 끝나는 시간을 분 단위로 자동적으로 계산한다. 또한, KOI 전자의 인공지능 오븐 앞면에는 사용자에게 훈제오리구이 요리가 끝나는 시각을 알려 주는 디지털 시계가 있다. 훈제오리구이를 시작하는 시각과 오븐구이를 하는 데 필요한 시간이 분단위로 주어졌을 때, 오븐구이가 끝나는 시각을 계산하는 프로그램을 작성하시오. 입력 첫째 줄에는 현재 시각이 나온다. 현재 시각은 시 A (0

    [백준/5586번] JOI와 IOI(JOI 2008)[Java]

    [백준/5586번] JOI와 IOI(JOI 2008)[Java]

    문제 입력으로 주어지는 문자열에서 연속으로 3개의 문자가 JOI 또는 IOI인 곳이 각각 몇 개 있는지 구하는 프로그램을 작성하시오. 문자열을 알파벳 대문자로만 이루어져 있다. 예를 들어, 아래와 같이 "JOIOIOI"에는 JOI가 1개, IOI가 2개 있다. 입력 첫째 줄에 알파벳 10000자 이내의 문자열이 주어진다. 출력 첫째 줄에 문자열에 포함되어 있는 JOI의 개수, 둘째 줄에 IOI의 개수를 출력한다. 풀이 문자열의 앞에서 부터 하나씩 , J가 나올시 O,I가 다음 열에 나오는지 확인하고 맞으면 cnt++해준다. 똑같은 방식으로 IOI도 반복해준뒤 출력해주면 완료. ㅇㅅㅇ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26..

    038 - Method Header Practice 3

    038 - Method Header Practice 3

    Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.*; class Main { public static String makeCapital(String name){ return name.toUpperCase(); } //test case below (dont change): public static void Bakjoon(..

    036 - Method Header Practice 1,2

    036 - Method Header Practice 1,2

    036 - Method Header Practice 1 Write a method header on line two with the following specs: Returns: an integer Name: practiceOne Parameters: none You should not be writing code on any line other than #2 Solution 1 2 3 4 5 6 7 8 9 10 11 12 import java.util.*; public class Main { public int practiceOne(){ { return 2; } } } 037 - Method Header Practice 2 Write a method header on line two with the f..

    035 - Sum Odds in Range

    035 - Sum Odds in Range

    You are given two inputs: int num1; int num2; You can assume that the following: num2 > num1 ==> TRUE You are to write a program that will calculate and print out the SUM OF ODD numbers in between num1 and num2 inclusive. Your output should all be on one line, separated by spaces. Sample input/output: #1: 3 #2: 11 Output: 35 #1: 4 #2: 20 Output: 96 #1: -2 #2: 6 Output: 8 Solution 1 2 3 4 5 6 7 8..

    034 - Big Number Program (From Decoding)

    034 - Big Number Program (From Decoding)

    You are given two inputs: int num1; int num2; You can assume that the following: num2 > num1 ==> TRUE You are to write a program that will print out all the ODD numbers in between num1 and num2 inclusive. Your output should all be on one line, separated by spaces. Sample input/output: #1: 3 #2: 11 3 5 7 9 11 #1: 4 #2: 20 5 7 9 11 13 15 17 19 #1: -2 #2: 6 -1 1 3 5 Solution 1 2 3 4 5 6 7 8 9 10 11..

    [백준/10990번] 별 찍기-15 [Java]

    [백준/10990번] 별 찍기-15 [Java]

    문제 예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요. 입력 첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다. 출력 첫째 줄부터 N번째 줄까지 차례대로 별을 출력한다. 풀이 앞에서 나오는 공간을 카운트 해주는 first_count, 그리고 별과 별 사이의 공간을 카운트 해주는 변수 last_count를 선언해주고 first_count는 개행될때마다 -1씩 해주고 last_count는 +1씩해주면서 카운트가 끝날때마다 별 하나를 찍어준다. ㅇㅅㅇ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import java.util.Scanner; class Bakjoon { public static void main(String[] args) throws Exce..

    026 - Further For Loop Practice 2 (skipping by 3s)

    026 - Further For Loop Practice 2 (skipping by 3s)

    Given the following inputs: int x; Write a for loop that will print out a series of numbers starting at 0 and ending before x, skipping 3 each time (excluding x). Sample input/outputs: In: 7 out: 0 3 6 In: 12 out: 0 3 6 9 In: 20 out: 0 3 6 9 12 15 18 HINT: You'll want to change the increment part of the for loop! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.*; class Bakjoon { public stat..