전체 글 (306)
2022-01-18 12:55:00
반응형

1. MyBatis 홈페이지 접속

https://blog.mybatis.org/

 

The MyBatis Blog

A blog about the the MyBatis data mapper framework.

blog.mybatis.org

 

2. Products →  Project → MyBatis 3 download link 마우스로 클릭

3. mybatis-3.5.9 → Assets → mybatis-3.5.9.zip 파일 다운로드

4. mybatis-3.5.9.zip 압축 해제 후 mybatis-3.5.9.jar 파일 확인

5. Eclipse에서 자바 프로젝트 생성 → 생성된 프로젝트 마우스로 우클릭 → [Build Path] → [Configure Build Path ...]

순으로 클릭

6. [Libraries] → [Add External JARs...] 마우스로 클릭

7. ojdbc6_g.jar 파일 열기

* 경로 : C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib

해당 경로는 버전에 따라 다를 수 있음

8. [Libraries] → [Add External JARs...] 다시 마우스로 클릭

9. mybatis-3.5.9.jar 파일 열기

10.  [Libraries] → ojdbc6_g.jar & mybatis-3.5.9.jar 확인 → Apply and Close 버튼 마우스로 클릭

11. Reterenced Libraries에 mybatis-3.5.9.jar와 ojdbc6_g.jar 생성 여부 확인

반응형

'AI Bootcamp > MyBatis' 카테고리의 다른 글

[MyBatis] 개념 정리  (0) 2022.01.19
2022-01-18 09:15:45
반응형

주식가격

 

 문제 설명

 

초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요.

 

 제한 사항

 

  • prices의 각 가격은 1 이상 10,000 이하인 자연수입니다.
  • prices의 길이는 2 이상 100,000 이하입니다.

 

 입출력 예

 

prices return
[1, 2, 3, 4, 5] [4, 3, 1, 1, 0]

 

 Python 코드

 

from collections import deque

def solution(prices):
    queue = deque(prices)  # prices로 queue를 초기화
    answer = []
    
    
    # 반복문 돌면서 앞에서부터 하나씩 popleft 한 뒤의 남은 queue를 순회하며 값이 작아지기 전까지
    # 초를 증가시키는 것을 queue가 빌때까지 반복
    while queue:
        price = queue.popleft() 
        sec = 0
        for q in queue:
            sec += 1
            if price > q:
                break 
        answer.append(sec)        
    return answer

* 참고 링크 : https://velog.io/@soo5717/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%A3%BC%EC%8B%9D%EA%B0%80%EA%B2%A9-Python

def solution(prices):
    answer = [0] * len(prices)
    stack = []

    for i, price in enumerate(prices):

        while stack and price < prices[stack[-1]]:
            j = stack.pop()
            answer[j] = i - j
        stack.append(i)

    while stack:
        j = stack.pop()
        answer[j] = len(prices) - 1 - j

    return answer

* 참고 링크 : 

def solution(prices):
    # answer = 몇초 후 가격이 떨어지는지 저장하는 배열
    answer = [len(prices)-i-1 for i in range(len(prices))]
    
    # stack = prices의 인덱스를 차례로 담아두는 배열
    stack = [0]
    
    for i in range(1, len(prices)):
        while stack:
            index = stack[-1]
            
            # 주식 가격이 떨어졌다면
            if prices[index] > prices[i]:
                answer[index] = i - index
                stack.pop()
            
            # 떨어지지 않았다면 다음 시점으로 넘어감 (주식 가격이 계속 증가하고 있다는 말)
            else:
                break
        
        # 스택에 추가한다.
        # 다음 시점으로 넘어갔을 때 다시 비교 대상이 될 예정이다.
        stack.append(i)
        
    return answer

* 참고 링크 : https://tngusmiso.tistory.com/34

 

 C++ 코드

 

#include <string>
#include <vector>
#include <stack>

using namespace std;

vector<int> solution(vector<int> prices) {
    vector<int> answer(prices.size());
    stack<int> s;
    int size = prices.size(); // 계속 size를 계산하는 것보다 상수값으로 저장하면 전체 함수 처리 시간 감소
    
    for (int i = 0; i < size; ++i){
        while (!s.empty() && prices[s.top()] > prices[i]){ // 가격이 줄어들었다면
            answer[s.top()] = i - s.top(); // 현재 시간 - 당시 시간
            s.pop();
        }
        s.push(i);
    }
    while (!s.empty()){
        answer[s.top()] = size - 1 - s.top(); // 종료 시간 - 당시 시간
        s.pop();
    }
    
    return answer;
}

* 참고 링크 : https://ssocoit.tistory.com/15

 

 출처

 

https://programmers.co.kr/learn/courses/30/lessons/42584

반응형
2022-01-17 22:51:15
반응형

기능개발

 

 문제 설명

 

프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다.

또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다.

먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇 개의 기능이 배포되는지를 return 하도록 solution 함수를 완성하세요.

 

 제한 사항

 

  • 작업의 개수(progresses, speeds배열의 길이)는 100개 이하입니다.
  • 작업 진도는 100 미만의 자연수입니다.
  • 작업 속도는 100 이하의 자연수입니다.
  • 배포는 하루에 한 번만 할 수 있으며, 하루의 끝에 이루어진다고 가정합니다. 예를 들어 진도율이 95%인 작업의 개발 속도가 하루에 4%라면 배포는 2일 뒤에 이루어집니다.

 

 입출력 예

 

progresses speeds return
[93, 30, 55] [1, 30, 5] [2, 1]
[95, 90, 99, 99, 80, 99] [1, 1, 1, 1, 1, 1] [1, 3, 2]

 

 Python 코드

 

import math # 수학과 관련된 함수들을 모아놓은 math 모듈 import

def solution(progresses, speeds):
    n = len(progresses)  # progresses 길이를 변수로 선언
    date_left = []       # 몇 일 남았는지 date_left라는 stack을 생성
    answer = []          # answer 배열로 생성
    
    for i in range(n):
        progress_left = 100 - progresses[i]   # 작업 진행률 확인
        share = math.ceil(progress_left / speeds[i]) # math.ceil() 함수를 이용한 올림
        date_left.append(share) # 몇 일 남았는지 share 몫을 구해 date_left append
        
# [7, 3, 9] -> 7보다 큰 값이 나올때까지 계속 더해줌 => result 2
# 0을 넣으면 left는 7이 되고 [3, 9]가 됨
# 7보다 큰 값이 나오면 탈출하여 answer.append(result)

# [9]
# answer = [2]
# left = 8 

# [9] -> []
# answer = [2, 1] // result default 값이 1이 들어감
    
    while date_left:
        left = date_left.pop(0)
        result = 1
        while len(date_left) != 0 and left >= date_left[0]: 
        # date_left의 길이가 0이 아니고, left가 date_left보다 크거나 같을 때
            result += 1        # 1일씩 추가
            date_left.pop(0)   # 추가 할 때마다 pop 시켜줌
        answer.append(result)  # 
        
    return answer

* 참고 링크 : https://www.youtube.com/watch?v=rdiXbJzgBPQ 

* math.ceil ( ) 함수 : 실수를 입력하면 올림하여 정수로 반환하는 함수

ceil은 천장을 의미하는 단어로 어떤 실수의 천장을 의미하는 바로 위 정수를 반환한다고 생각하면 좋다.

math.ceil(3.14)
# result : 4

math.ceil(-3.14)
# result : -3

math.ceil(0.15)
# result : 1

math.ceil(-0.15)   
# result : 0

math.ceil(3)  # 정수는 그대로 정수로 반환
# result : 3

math.ceil(-3)
# result : -3

* 참고 링크 : https://ooyoung.tistory.com/99

* pop ( ) 함수 : 리스트의 맨 마지막 요소를 돌려주고 그 요소는 삭제한다.

a = [1,2,3]
a.pop()     # result : 3
a           # result : [1, 2]

* 참고 링크 : https://wikidocs.net/14#pop

* append ( ) 함수 : append를 사전에서 검색해 보면 "덧붙이다, 첨부하다"라는 뜻이 있다. append(x)는 리스트의 맨 마지막에 x를 추가하는 함수이다.

a = [1, 2, 3]
a.append(4)
a
# result : [1, 2, 3, 4]

리스트 안에는 어떤 자료형도 추가할 수 있다.

다음 예는 리스트에 다시 리스트를 추가한 결과이다.

a.append([5,6])
a
# result : [1, 2, 3, 4, [5, 6]]

* 참고 링크 : https://wikidocs.net/14#append

 

 C++ 코드

 

#include <string>
#include <vector>
#include <queue>
 
using namespace std;
 
vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    //현재 진척도
    queue<int> current;
    //큐에 옮기기
    for (auto p : progresses)
        current.push(p);
    while (!current.empty()){
        //진척도 추가
        for (int i = 0; i < current.size(); i++){
            int p = current.front();
            current.pop();
            current.push(p + speeds.at(i));
        }
        int count = 0;
        //큐 내부검사
        while (true){
            //진척도가 100퍼센트 이상이라면 큐에서 제거하고 카운트 증가
            if (current.size() >0 && current.front() >= 100){
                current.pop();
                speeds.erase(speeds.begin());
                count++;
                continue;
            }
            break;
        }
        //카운트가 한개이상 올라갔다면
        //정답리스트에 몇개가 배포되는지 추가
        if (count > 0)
            answer.push_back(count);
    }
    return answer;
}

 

* 참고 링크 : https://mungto.tistory.com/197

 

 출처

 

https://programmers.co.kr/learn/courses/30/lessons/42586

반응형
2022-01-17 00:44:12
반응형

다리를 지나는 트럭

 

 문제 설명

 

트럭 여러 대가 강을 가로지르는 일차선 다리를 정해진 순으로 건너려 합니다.

모든 트럭이 다리를 건너려면 최소 몇 초가 걸리는지 알아내야 합니다.

다리에는 트럭이 최대 bridge_length대 올라갈 수 있으며, 다리는 weight 이하까지의 무게를 견딜 수 있습니다.

단, 다리에 완전히 오르지 않은 트럭의 무게는 무시합니다.

예를 들어, 트럭 2대가 올라갈 수 있고 무게를 10kg까지 견디는 다리가 있습니다.

무게가 [7, 4, 5, 6]kg인 트럭이 순서대로 최단 시간 안에 다리를 건너려면 다음과 같이 건너야 합니다.

경과 시간 다리를 지난 트럭 다리를 건너는 트럭 대기 트럭
0 [] [] [7,4,5,6]
1~2 [] [7] [4,5,6]
3 [7] [4] [5,6]
4 [7] [4,5] [6]
5 [7,4] [5] [6]
6~7 [7,4,5] [6] []
8 [7,4,5,6] [] []

 

따라서, 모든 트럭이 다리를 지나려면 최소 8초가 걸립니다.

solution 함수의 매개변수로 다리에 올라갈 수 있는 트럭 수 bridge_length, 다리가 견딜 수 있는 무게 weight, 트럭 별 무게 truck_weights가 주어집니다.

이때 모든 트럭이 다리를 건너려면 최소 몇 초가 걸리는지 return 하도록 solution 함수를 완성하세요.

 

 제한 사항

 

  • bridge_length는 1 이상 10,000 이하입니다.
  • weight는 1 이상 10,000 이하입니다.
  • truck_weights의 길이는 1 이상 10,000 이하입니다.
  • 모든 트럭의 무게는 1 이상 weight 이하입니다.

 

 입출력 예

 

bridge_length weight truck_weights return
2 10 [7,4,5,6] 8
100 100 [10] 101
100 100 [10,10,10,10,10,10,10,10,10,10] 110

 

 Python 코드

 

# 시간 초과 코드

def solution(bridge_length, weight, truck_weights):
    answer = 0
    bridge = [0] * bridge_length # 다리 위의 리스트를 선언
    
    while len(bridge):
        answer += 1   # 1초씩 증가
        bridge.pop(0) # 다리 왼쪽 끝의 트럭을 pop
        if truck_weights: # 대기하는 트럭이 있다면
            bridge.append(truck_weights.pop(0)) # 다리에 트럭 추가
        else:
            bridge.append(0) # 무게가 아니라면 다리에 아무도 가지 않는다.
    return answer

* 참고 링크 1 : https://par3k.tistory.com/224

from collections import deque

def solution(bridge_length, weight, truck_weights):
    truck_weights = deque(truck_weights)   # truck_weights(대기트럭)을 담을 deque 생성
    bridge = deque([0 for _ in range(bridge_length)]) # 다리 길이만큼 0을 채워서 변수 생성 // 다리를 건너는 트럭
    time = 0           # 경과 시간
    bridge_weight = 0  # 지금 다리 위의 무게 // 현재 다리를 건너고 있는 무게

    while len(bridge) != 0:
        out = bridge.popleft() # 다리를 건너는 첫번째 트럭(bridge[0])를 pop 해줌
        bridge_weight -= out # 다리 무게에서 다리를 건넌 트럭의 무게를 빼줌
        time += 1 # 시간을 더해줌
        if truck_weights:  # deque에 요소가 남아 있으면 True
            # 현재 다리를 건너는 트럭의 무게와 다리에 오를 트럭의 무게의 합이
            if bridge_weight + truck_weights[0] <= weight:
                # 다리가 견딜 수 있는 무게 이하일 때
                left = truck_weights.popleft() # 대기트럭 deque에서 다음 트럭을 pop하고
                bridge_weight += left # 다리를 건너고 있는 트럭 무게에 더하고
                bridge.append(left) # 건너는 트럭 리스트에 넣어준다.
            else:
                # 다리가 견딜 수 있는 무게 초과일 때
                bridge.append(0) # 다음 트럭이 지나가지 못하므로 0을 채워준다.
    return time

* 참고 링크 2 : https://coblin.xyz/29

 

* 그림 설명 참고 링크 : https://eunhee-programming.tistory.com/149

* 참고 링크 3 : https://latte-is-horse.tistory.com/130

* 유튜브 설명 링크 : https://www.youtube.com/watch?v=Y9HYe4cUiZM&t=388s 

* deque 

  • 양쪽 끝에서 빠르게 추가와 삭제를 할 수 있는 리스트류 컨테이너
  • 양방향 큐
  • 데이터의 회전도 가능
  • maxlen을 설정하여 최대 항목 수를 설정

* 참고 링크 4 : https://www.youtube.com/watch?v=05roQ6gFwsM 

 C++ 코드

 

#include <queue>
#include <vector>

using namespace std;

int solution(int bridge_length, int weight, vector<int> truck_weights) {
    int answer = 0;
    
    int idx=0;    //차량 지목용 idx
    int sum=0;   //현재 다리에 올라와있는 차량 무게 총합
    queue<int> q;  //현재 다리를 건너는 트럭 체크용 큐
    
    while(1){
        
        if(idx == truck_weights.size()){  //마지막 트럭일 때
            answer += bridge_length;  //마지막 트럭이 지나는 시간 추가
            break;  
        }
        
        answer++; //시간초 증가
        int tmp = truck_weights[idx];
        
        //차가 다리를 다 건넜을 경우
        if(q.size() == bridge_length){
            sum -= q.front();  //다 건넜으니 현재 다리에 있는 차들의 무게에서 제외
            q.pop();  
        }
        
        if(sum + tmp <= weight){  //다리에 다음 차가 진입할 수 있다면
            sum += tmp;  //차량 무게 추가
            q.push(tmp);  
            idx++;  //다음 차량을 위해서
        }else{   
            q.push(0);  //진입할 수 없다면 0을 푸시해서 시간초 계산
        }
    }
   
    return answer;
}

 

* 참고 링크 : https://velog.io/@qhsh866/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4Level2-%EB%8B%A4%EB%A6%AC%EB%A5%BC-%EC%A7%80%EB%82%98%EB%8A%94-%ED%8A%B8%EB%9F%AD-C

 

 출처

 

https://programmers.co.kr/learn/courses/30/lessons/42583

반응형
2022-01-14 08:59:30
반응형

43. Multiply Strings

 

 문제 설명

 

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.

 

 제한 사항

 

  • 1 <= num1.length, num2.length <= 200
  • num1 and num2 consist of digits only.
  • Both num1 and num2 do not contain any leading zero, except the number 0 itself.

 

 입출력 예

 

Example 1:

Input: num1 = "2", num2 = "3"
Output: "6"

Example 2:

Input: num1 = "123", num2 = "456"
Output: "56088"

 

 Python 코드

 

Python code 

class Solution:
    def multiply(self, num1: str, num2: str) -> str:
        def str_to_int(num_str):
            num = 0
            for i, c in enumerate(num_str[::-1]):
                num += pow(10, i) * (ord(c) - ord('0'))
            return num

        return str(str_to_int(num1) * str_to_int(num2))

* 참고 링크 : https://wellsw.tistory.com/94?category=1054641

 

 C++ 코드

 

C ++ code

class Solution {
public:
	string multiply(string num1, string num2) {
		string res(num1.size() + num2.size(), '0');
		for (int i = num1.size() - 1; i >= 0; --i) {
			int carry = 0;
			for (int j = num2.size() - 1; j >= 0; --j) {
				int tmp = (res[i + j + 1] - '0') + (num2[j] - '0')*(num1[i] - '0') + carry;
				res[i + j + 1] = tmp % 10 + '0';
				carry = tmp/10;
			}
			res[i] += carry;
		}
		auto pos = res.find_first_not_of('0');
		if (pos == string::npos)
			return "0";
		return res.substr(pos, res.length() - pos);
	}
};

* 참고 링크 : https://blog.fearcat.in/a?ID=00850-66ef66e8-11ca-463c-82ae-c4af5cb77fae

 

 출처

 

https://leetcode.com/problems/multiply-strings/

반응형
2022-01-14 07:12:08
반응형

Remove Element

 

 문제 설명

 

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.

Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result. It does not matter what you leave beyond the first k elements.

Return k after placing the final result in the first k slots of nums.

Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.

Custom Judge:

The judge will test your solution with the following code:

int[] nums = [...]; // Input array
int val = ...; // Value to remove
int[] expectedNums = [...]; // The expected answer with correct length.
                            // It is sorted with no values equaling val.

int k = removeElement(nums, val); // Calls your implementation

assert k == expectedNums.length;
sort(nums, 0, k); // Sort the first k elements of nums
for (int i = 0; i < actualLength; i++) {
    assert nums[i] == expectedNums[i];
}

If all assertions pass, then your solution will be accepted.

 제한 사항

 

  • 0 <= nums.length <= 100
  • 0 <= nums[i] <= 50
  • 0 <= val <= 100

 

 입출력 예

 

Example 1:

Input: nums = [3,2,2,3], val = 3
Output: 2, nums = [2,2,_,_]
Explanation: Your function should return k = 2, with the first two elements of nums being 2.
It does not matter what you leave beyond the returned k (hence they are underscores).

Example 2:

Input: nums = [0,1,2,2,3,0,4,2], val = 2
Output: 5, nums = [0,1,4,0,3,_,_,_]
Explanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4.
Note that the five elements can be returned in any order.
It does not matter what you leave beyond the returned k (hence they are underscores).

 

 Python 코드

 

Python code 

class Solution: 
    def removeElement(self, nums: List[int], val: int) -> int:
        answer = [num for num in nums if num != val] 
        for i in range(len(answer)): 
            nums[i] = answer[i] 
            
        nums = nums[:len(answer)] 
        return len(nums)

 

* 참고 링크 : https://somjang.tistory.com/entry/leetCode-27-Remove-Element-Python

https://redquark.org/leetcode/0027-remove-element/

class Solution:
    def removeElement(self, nums, val):
        for i in range(len(nums)):
            if nums[0] != val:
                nums.append(nums[0])
                del nums[0]
            else:
                del nums[0]
        return len(nums)

* 참고 링크 : https://bortfolio.tistory.com/124

 C++ 코드

 

C ++ code

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int count = 0;
        for(int i = 0; i < nums.size(); i++){
            if (nums[i] != val){
                nums[count++] = nums[i];
            }
        }
        return count;
    }
};

* 참고 링크 : https://egbert-yu-ting.github.io/posts/1afffcb4/

https://lessbutbetter.tistory.com/entry/LeetCodeEasyC%EB%AC%B8%EC%A0%9C%ED%92%80%EC%9D%B4-27-Remove-Element

 출처

 

https://leetcode.com/problems/remove-element/

반응형