코딩배우는 학생

    057 - Accumulator Method String Challenge 1 (optional)

    057 - Accumulator Method String Challenge 1 (optional)

    Write a method header on line two with the following specs: Returns: a String Name: surroundStr Parameters: a String called s a String called search_term Then complete the method by programming the following behavior Return a new String built from s that has every instance of the search term surrounded by parentheses See below examples. Examples: surroundStr("abcabcabc","abc") ==> "(abc)(abc)(ab..

    056 - Accumulator Method String Practice 4

    056 - Accumulator Method String Practice 4

    Write a method header on line two with the following specs: Returns: a String Name: surround Parameters: a String called s a char called search_term Then complete the method by programming the following behavior Return a new String built from s that has every instance of the search term surrounded by parentheses See below examples. Examples: surround("abcabcabc",'c') ==> "ab(c)ab(c)ab(c)" surrou..

    055 - Accumulator Method String Practice 3

    055 - Accumulator Method String Practice 3

    Write a method header on line two with the following specs: Returns: a String Name: censorLetter Parameters: a String called s a char called ch Then complete the method by programming the following behavior Replace all instances of ch with a "*" within the String s. See below examples. Examples: censorLetter("computer science",'e') ==> "comput*r sci*nc*" censorLetter("trick or treat",'t') ==> "*..

    054 - Accumulator Method String Practice 2

    054 - Accumulator Method String Practice 2

    Write a method header on line two with the following specs: Returns: a String Name: thirdLetter Parameters: a String called s Then complete the method by programming the following behavior Returns every 3rd letter of the String s, starting the first letter. See below examples. Examples: thirdLetter("hello there") ==> "hltr" thirdLetter("technology") ==> "thly" Solution 1 2 3 4 5 6 7 8 9 10 11 12..

    053 - Accumulator Method String Practice 1

    053 - Accumulator Method String Practice 1

    Write a method header on line two with the following specs: Returns: a String Name: spaceOut Parameters: a String called s Then complete the method by programming the following behavior Insert spaces after every character in the String s, then return the new string. See below examples (note the space at the end as well). Examples: spaceOut("hello") ==> "h e l l o " spaceOut("technology") ==> "t ..

    052 - Accumulator Method Challenge 2 (optional)

    052 - Accumulator Method Challenge 2 (optional)

    Write a method header on line two with the following specs: Returns: a String Name: alphabetical Parameters: a String called str Purpose: Return a string that is composed of each letter as long as the letter is later on in the alphabet than its previous one. You can assume actual parameters are lowercase. See below examples. Additional Info: You can use to compare characters (not Strings..

    051 - Accumulator Method Challenge 1 (optional)

    051 - Accumulator Method Challenge 1 (optional)

    Write a method header on line two with the following specs: Returns: an integer Name: countString Parameters: a String called str a String called toFind Purpose: Count the number of occurrences of toFind within str. See below examples. Examples: countString("crazy crayfish crushing craniums", "cra") ==> 3 countString("sometimes solutions dont come on time", "me") ==> 4 Solution 1 2 3 4 5 6 7 8 9..

    050 - Accumulator Method Practice 6

    050 - Accumulator Method Practice 6

    Write a method header on line two with the following specs: Returns: a String Name: keepVowels Parameters: a String called s Purpose: create a string that is composed of all the vowels in the string, in the same order that they appear. see below examples for clarity. Examples: keepVowels("hello") ==> "eo" keepVowels("how do i internets") ==> "ooiiee" Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ..

    049 - Accumulator Method Practice 5

    049 - Accumulator Method Practice 5

    Write a method header on line two with the following specs: Returns: an integer Name: countVowels Parameters: a String called s Purpose: count the number of vowels in the string s. Assume s is all lowercase. Examples: countVowels("obama") ==> 3 countVowels("happy friday! i love weekends") ==> 9 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 class Main { public static int..

    048 - Accumulator Method Practice 4

    048 - Accumulator Method Practice 4

    Write a method header on line two with the following specs: Returns: an integer Name: countA Parameters: a String called s Purpose: count the number of occurrences of 'a' or 'A' within s Examples: countA("aaa") ==> 3 countA("aaBBdf8k3AAadnklA") ==> 6 Hint: How do you write a for loop to loop through every letter of a string? You've done this multiple times already :) 1 2 3 4 5 6 7 8 9 10 11 12 1..

    047- Accumulator Method Practice 3

    047- Accumulator Method Practice 3

    Write a method header on line two with the following specs: Returns: an integer Name: sumFivesRange Parameters: an integer called "a" that represents the beginning of the range an integer called "b" that represents the end of the range Purpose: calculate the sum of the multiples of 5 within the range a to b inclusive (including b) Examples: sumFivesRange(5,15) ==> 30 sumFivesRange(11,28) ==> 60 ..

    046 - Accumulator Method Practice 2

    046 - Accumulator Method Practice 2

    Write a method header on line two with the following specs: Returns: an integer Name: sumEvenToX Parameters: an integer called "x" Purpose: calculate the sum of the EVEN integers from 1 to x (including x) Examples: sumEvenToX(5) ==> 6 sumEvenToX(8) ==> 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import java.io.*; import java.util.*; import java.util.stream.*; class Main { public ..

    [백준/2751번] 수 정렬하기 2 [Java]

    [백준/2751번] 수 정렬하기 2 [Java]

    문제 N개의 수가 주어졌을 때, 이를 오름차순으로 정렬하는 프로그램을 작성하시오. 입력 첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 숫자가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다. 출력 첫째 줄부터 N개의 줄에 오름차순으로 정렬한 결과를 한 줄에 하나씩 출력한다. 풀이 단순 정렬 문제. 하지만 시간초과가 있어서 애를 먹었다. 정렬을 이용해서 풀어야할 것같은데, 귀찮아서 처음에는 Array를 선언, Arrays.sort를 사용해서 풀어줫는데 시간초과가 나서 List를 이용해, Collections.sort를 사용해보았다. 이건 통과. Array보다 List가 더 빠르다는 것을 알 수 있었던 문제였다..

    [백준/18229번]내가 살게, 아냐 내가 살게(인천대 INU 송년 코드페스티벌 2019) [Java]

    [백준/18229번]내가 살게, 아냐 내가 살게(인천대 INU 송년 코드페스티벌 2019) [Java]

    문제 N명이 서로 결제하겠다며 카드를 내밀고 있다. 사람들과 점원의 거리는 K이다. 처음으로 손을 K이상 뻗은 사람은 결제하게 되는 영예를 얻는다. 사람들은 다음과 같은 과정으로 손을 뻗는다. 1번 사람이 손을 A1,1만큼 뻗는다. → 2번 사람이 손을 A2,1만큼 뻗는다. → 3번 사람이 손을 A3,1만큼 뻗는다. → ...... → N번 사람이 손을 AN,1만큼 뻗는다. → 1번 사람이 손을 A1,2만큼 추가로 뻗는다. → 2번 사람이 손을 A2,2만큼 추가로 뻗는다. → ...... → N번 사람이 손을 AN,M만큼 추가로 뻗는다. 여기서 A는 2차원 배열의 형태로 입력으로 주어진다. 다시 말해, 1번부터 N번 사람까지 순서대로 손을 뻗는 것을 M번 반복하며, 각 순서에서 손을 뻗는 정도는 입력으로..

    [백준/18228번] 펭귄추락대책위원회(인천대 INU 송년 코드페스티벌 2019)[Java]

    [백준/18228번] 펭귄추락대책위원회(인천대 INU 송년 코드페스티벌 2019)[Java]

    문제 일우는 친구들과 펭귄 얼음깨기 게임을 하고 있다. 계속 떨어지는 펭귄이 불쌍했던 일우는 INU 송년 코드페스티벌 참가자들을 펭귄추락대책위원회로 초대했다. 이 펭귄 얼음깨기는 리메이크 된 버전으로, N개의 얼음이 1부터 N까지 번호가 매겨져 있다. 게임은 얼음 1부터 N까지 순서대로 일렬로 나열된 공간에서 진행된다. 게임 시작 시, 펭귄 한 마리가 임의의 얼음 K위에 위치한다. 참가자는 몇 개의 얼음을 깨뜨려서 펭귄을 떨어뜨리는 것이 목적이다. 단, 펭귄이 밟고 있는 얼음은 깨뜨릴 수 없다. 각 얼음은 서로 다른 강도를 가지고 있어서 얼음 i(1 ≤ i ≤ N)를 깨뜨리는 데에 Ai만큼의 힘이 필요하다. 양옆으로 인접해 있는 얼음들을 하나의 그룹으로 봤을 때, 그룹의 끝이 얼음1 또는 N을 포함하지 ..

    [백준/10250번] ACM호텔(Daejeon Nationalwide Internet Competition 2014 ) [Java]

    [백준/10250번] ACM호텔(Daejeon Nationalwide Internet Competition 2014 ) [Java]

    문제 ACM 호텔 매니저 지우는 손님이 도착하는 대로 빈 방을 배정하고 있다. 고객 설문조사에 따르면 손님들은 호텔 정문으로부터 걸어서 가장 짧은 거리에 있는 방을 선호한다고 한다. 여러분은 지우를 도와 줄 프로그램을 작성하고자 한다. 즉 설문조사 결과 대로 호텔 정문으로부터 걷는 거리가 가장 짧도록 방을 배정하는 프로그램을 작성하고자 한다. 문제를 단순화하기 위해서 호텔은 직사각형 모양이라고 가정하자. 각 층에 W 개의 방이 있는 H 층 건물이라고 가정하자 (1 ≤ H, W ≤ 99). 그리고 엘리베이터는 가장 왼쪽에 있다고 가정하자(그림 1 참고). 이런 형태의 호텔을 H × W 형태 호텔이라고 부른다. 호텔 정문은 일층 엘리베이터 바로 앞에 있는데, 정문에서 엘리베이터까지의 거리는 무시한다. 또 모..

    [백준/10773번] 제로(CCC 2015 Senior Division) [Java]

    [백준/10773번] 제로(CCC 2015 Senior Division) [Java]

    문제 나코더 기장 재민이는 동아리 회식을 준비하기 위해서 장부를 관리하는 중이다. 재현이는 재민이를 도와서 돈을 관리하는 중인데, 애석하게도 항상 정신없는 재현이는 돈을 실수로 잘못 부르는 사고를 치기 일쑤였다. 재현이는 잘못된 수를 부를 때마다 0을 외쳐서, 가장 최근에 재민이가 쓴 수를 지우게 시킨다. 재민이는 이렇게 모든 수를 받아 적은 후 그 수의 합을 알고 싶어 한다. 재민이를 도와주자! 입력 첫 번째 줄에 정수 K가 주어진다. (1 ≤ K ≤ 100,000) 이후 K개의 줄에 정수가 1개씩 주어진다. 정수는 0에서 1,000,000 사이의 값을 가지며, 정수가 "0" 일 경우에는 가장 최근에 쓴 수를 지우고, 아닐 경우 해당 수를 쓴다. 정수가 "0"일 경우에 지울 수 있는 수가 있음을 보장할..

    [백준/17173번] 배수들의 합(충남대 3회 생각하는 프로그래밍 대회)[Java]

    [백준/17173번] 배수들의 합(충남대 3회 생각하는 프로그래밍 대회)[Java]

    문제 신원이는 백준에서 배수에 관한 문제를 풀다가 감명을 받아 새로운 문제를 만들어보았다. 자연수 N과 M개의 자연수 Ki가 주어진다. Ki중 적어도 하나의 배수이면서 1 이상 N 이하인 수의 합을 구하여라. 입력 첫 번째 줄에 N과 M가 주어진다. (2 ≤ N ≤ 1000, 1 ≤ M < N) 그다음 줄에 M개의 정수 Ki가 주어진다. (2 ≤ Ki ≤ 1000) 동일한 Ki는 주어지지 않으며, 오름차순으로 정렬되어있다. 출력 배수들의 합을 출력한다. 풀이 정수 N을 선언받은 뒤 1부터 N까지의 수 중 따로 선언받은 M개의 정수 K에 나누어 떨어지는 수의 총합을 구하는 문제이다. 예를들어 N=10 M=2일때 K를 2와 3을 입력 받았다면 1~10중 2와 3으로 나누어떨어지는 수만을 더하면 42가 도출된..

    [백준/17530번] Buffon(Maratona de Programação SBC 2019)[Java]

    [백준/17530번] Buffon(Maratona de Programação SBC 2019)[Java]

    Problem The Kingdom of Matchings is governed by a generous commander. The commander’s fame and great qualities are known to all, including neighboring kingdoms. One of his most famous qualities is his good humor, which is nourished daily by a court buffoon, elected annually at the Great Comedy Contest (GCC) of the kingdom. The court buffoon helps to relieve all the tension of the various politic..

    [백준/15740번] A+B - 9 [Java]

    [백준/15740번] A+B - 9 [Java]

    문제 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. 입력 첫째 줄에 A와 B (-1010000 ≤ A, B ≤ 1010000)가 주어진다. 출력 첫째 줄에 A+B를 출력한다. 서브태스크 1 (5점) 0 ≤ A, B ≤ 10 서브태스크 2 (10점) -100 ≤ A, B ≤ 100 서브태스크 3 (10점) 0 ≤ A, B ≤ 109 서브태스크 4 (15점) -109 ≤ A, B ≤ 109 서브태스크 5 (15점) 0 ≤ A, B ≤ 260 서브태스크 6 (20점) -260 ≤ A, B ≤ 260 서브태스크 7 (20점) 0 ≤ A, B ≤ 1010000 서브태스크 8 (5점) -1010000 ≤ A, B ≤ 1010000 풀이 처음에 단순 계산 문제인 줄 알고 당연하게 int..