CS (53) 썸네일형 리스트형 시간 계산하기(손코딩) 수정전 ver1 public class Time { public static void main(String[] args) { System.out.println(solution("23:55:45","07:03")); } public static int cal(String time){ char[] arr = time.toCharArray(); int sum = 0; sum += Integer.parseInt(arr[0])*10*3600; sum += Integer.parseInt(arr[1])*3600; sum += Integer.parseInt(arr[3])*10*60; sum += Integer.parseInt(arr[4])*60; sum += Integer.parseInt(arr[6])*10; sum .. 재귀함수와 반복문의 차이점 피보나치 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/12945 피보나치 문제를 푸는 경우 재귀함수를 이용하거나 반복문을 이용해서 해결할 수 있다. 피보나치 class Solution { static int[] memo; public int solution(int n) { memo = new int[n+1]; int answer = fibo(n); return answer; } public int fibo(int n){ if(n==0){ return 0; } if(n==1){ return 1; } // 메모이제이션 작업(피보나치 이전 결과를 배열에 저장) if(memo[n]!=0){ return memo[n]; } memo[n]=(fib.. 소수 구하기 1000까지 소수를 구해보자 버전 1) 총 연산횟수는 78022 public class PrimeNumber1 { public static void main(String[] args) { int count=0; second: for(int i=2;i 소인수분해 https://school.programmers.co.kr/learn/courses/30/lessons/120852 [프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr](https://school.programmers.co.kr/learn/courses/30/lessons/120852) import java.util.*; class Solution { public int[] solution(int n) { List list = new ArrayList(); int i = 2; while(n>1){ if(n%i==0){ list.add(i); n = n/i; .. 중앙값 구하기 import java.util.Scanner; public class Median { // 3개의 정숫값을 입력하고 중앙값을 구하기 static int med3(int a, int b, int c){ if(a >= b){ if(b >= c) return b; else if (a c) return a; else if( b>c) return c; else return b; } public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println("세 정수의 중앙값을 구합니다"); System.out.println("a의 값 : "); int a = stdIn.nextInt(); System.out.p.. 문자열 치환 String::replaceAll 공부하기 문자열 조작시 많이 사용된다. replace와 replaceAll의 차이점: String replace(char oldChar, char newChar) : oldChar : 찾을 문자열 , newChar : 새로운 문자열 String replaceAll(String regex, String replacement) 정규식또는 기존문자 , 대체문자 (정규식을 사용하면 정규식을 인식한다. 문자인 경우에는 replace와 같은 역할) 예제) String str = "안녕하세요. 반가워요. 또 놀러오세요."; str = str.replace(".", "^^"); System.out.println(str); // 결과 : 안녕하세요^^ 반가워요^^ 또 놀러오세요^^ St.. 2중 for문 주의점 class Solution { public int solution(int n) { int answer = 0; for(int j =1; j 알고리즘 스터디 문제 1,2(기수변환) 기한) 2023.09.11(월) ~ 09.17(일) 10PM 문제1. 아래 예시처럼 기수 변환 과정을 자세히 나타내는 프로그램을 작성하세요. (아래 예시의 59, 2라는 값은 Scanner로 입력 받은 값입니다.) Console창) 10진수를 기수 변환합니다. 변환하는 음이 아닌 정수 : 59 어떤 진수로 변환할까요? (2~36): 2 2 | 59 +————- 2 | 29 •••1 +————- (•••생략•••) 2 | 1 •••1 +————- 0 •••1 2진수로 111011입니다. 문제2. 124 나라가 있습니다. 124 나라에서는 10진법이 아닌 다음과 같은 자신들만의 규칙으로 수를 표현합니다. 124 나라에는 자연수만 존재합니다. 124 나라에는 모든 수를 표현할 때 1, 2, 4만 사용합니다. .. 이전 1 2 3 4 5 6 7 다음