전체 글
-
3.3장React/실전 리액트 프로그래밍 2023. 2. 3. 23:56
3.3 리액트 훅 기초 익히기 함수형 컴포넌트에 기능을 추가할 때 사용한다. 상태값을 사용할 수 있고, 자식 요소에 접근할 수 있다. 훅이 주는 장점이 되게 다양하고 적극적으로 개발 진행중이라고 한다. 3.3.1 상태값 추가하기 : useState useState를 사용하면 배열을 반환해주고 배열의 첫 번쨰 원소는 상태값, 두 번째 원소는 상태값 변경 함수다. 상태값 변경함수가 호출 될 경우 해당 컴포넌트를 다시 렌더링하고 자식도 같이 렌더링 된다. 상태값 변경 함수는 비동기 동작을 진행하며 배치처리를 진행하여 한번에 처리한다. function MyComponent() { const [count, setCount] = useState({ value : 0}); function onClick() { set..
-
3.2장React/실전 리액트 프로그래밍 2023. 2. 3. 23:54
3.2 리액트 요소와 가상 돔 리액트 요소는 UI를 표현하는 수단이다. 렌더링 성능을 높이기 위해 가상 돔을 활용한다. 기존의 방식은 돔을 변경하면 돔을 다시렌더링 하지만 리액트의 경우 메모리에 가상돔을 생성하여 기존의 돔과 비교한 후 변경된 점만 찾아서 실제 돔에 렌더링 해주는 방식을 사용한다. 3.2.1 리액트 요소 이해하기 JSX 코드 createElement 변환 과정 이해하기 const element = click here; const element = React.createElement( 'a', { href: 'http://google.com' }, 'click here', ); JSX 코드가 createElement 코드로 변환되는 과정이다 한개 더 예시를 살펴보자 const element..
-
3.1장React/실전 리액트 프로그래밍 2023. 2. 3. 23:53
3.1 상태값과 속성값으로 관리하는 UI(User Interface) 데이터 UI(User Interface) 데이터를 컴포넌트 내부에서 관리되는 상태값과 부모 컴포넌트에서 내려주는 속성값으로 관리한다. 리액트를 사용하기 위해서는 결국 상태값과 속성값을 이용해서 구현해야 한다. UI(User Interface) 데이터가 변경되면 화면을 다시 나타내야 한다. UI 데이터가 변동될 때마다 돔 요소들을 직접 수정해야하며 수정하다 보면 코드가 섞이게 되고 복잡해지게 된다. 리액트는 화면의 모든 코드를 컴포넌트 함수에 선언형으로 작성하여 UI 데이터 변경을 감지하여 컴포넌트 함수를 이용해 화면을 자동으로 갱신해준다. 3.1.1 리액트를 사용한 코드의 특징 할 일 목록 추가 서버에 저장> 초기 화면을 구현하고 to..
-
2720. [Python]세탁소 사장 동혁Python_알고리즘/Bronze III 2023. 2. 3. 23:47
1. 문제 https://www.acmicpc.net/problem/2720 2720번: 세탁소 사장 동혁 각 테스트케이스에 대해 필요한 쿼터의 개수, 다임의 개수, 니켈의 개수, 페니의 개수를 공백으로 구분하여 출력한다. www.acmicpc.net 2. 접근 방법 시간 제한: 1초 메모리 제한: 128MB Greedy Algorith(탐욕 알고리즘) 3. 파이썬 코드 N = int(input()) # 돈 단위가 1.00$ 달러가아닌 100으로 표현되서 각 돈에 100을 곱한 리스트 생성 money = [25, 10, 5, 1] for _ in range(N): # 들어온 input 돈을 money 리스트를 반복해가며 몫을 출력하고 나머지를 payback 에 넣어줌 payback = int(input(..
-
14916. [Python]거스름돈Python_알고리즘/Silver V 2023. 2. 2. 23:44
1. 문제 https://www.acmicpc.net/problem/14916 14916번: 거스름돈 첫째 줄에 거스름돈 액수 n(1 ≤ n ≤ 100,000)이 주어진다. www.acmicpc.net 2. 접근 방법 시간 제한: 2초 메모리 제한: 512MB Greedy Algorith(탐욕 알고리즘) 3. 파이썬 코드 N = int(input()) cnt = 0 first_value = N # N 값이 5보다 작은 경우 2로 나눈 몫과 나머지 출력 if N < 5: cnt += N//2 N = N%2 if N == 0: print(cnt) else: print(-1) else: # N 값이 5보다 큰 경우 cnt 에 5로 나눈 몫을 넣고 나머지를 N에 넣어줘서 2로 똑같은 작업 수행 for i in ..
-
1439. [Python]뒤집기Python_알고리즘/Silver V 2023. 2. 1. 22:55
1. 문제 https://www.acmicpc.net/problem/1439 1439번: 뒤집기 다솜이는 0과 1로만 이루어진 문자열 S를 가지고 있다. 다솜이는 이 문자열 S에 있는 모든 숫자를 전부 같게 만들려고 한다. 다솜이가 할 수 있는 행동은 S에서 연속된 하나 이상의 숫자를 잡고 모 www.acmicpc.net 2. 접근 방법 시간 제한: 2초 메모리 제한: 128MB 문자열 카운트 3. 파이썬 코드 N = input() # 값을 비교할 문자열 변수 생성 check = "" # 갯수를 카운트할 변수 생성 cnt = 1 # 문자열 반복 시작 for i in N: # 처음 값을 시작했을 경우 if check == "": # 비교할 문자열 변수에 i 값을 넣어줌 check = i # 처음이 아닌 경..
-
10610. [Python]30Python_알고리즘/Silver IV 2023. 1. 31. 23:52
1. 문제 https://www.acmicpc.net/problem/10610 10610번: 30 어느 날, 미르코는 우연히 길거리에서 양수 N을 보았다. 미르코는 30이란 수를 존경하기 때문에, 그는 길거리에서 찾은 수에 포함된 숫자들을 섞어 30의 배수가 되는 가장 큰 수를 만들고 싶어한 www.acmicpc.net 2. 접근 방법 시간 제한: 1초 메모리 제한: 256MB 문자열 정렬 조건 3. 파이썬 코드 N = input() # 숫자를 담을 리스트 생성 num_list = [] # 30으로 나눠야기 때문에 3의 배수인지 확인하는 변수 생성 total = 0 # 정답 출력할 문자 변수 선언 ans = "" # 30의 배수이므로 30보다 작으면 -1 출력 if int(N) < 30: print(-1..
-
1789. [Python]수들의 합Python_알고리즘/Silver IV 2023. 1. 30. 22:24
1. 문제 https://www.acmicpc.net/problem/1789 1789번: 수들의 합 첫째 줄에 자연수 S(1 ≤ S ≤ 4,294,967,295)가 주어진다. www.acmicpc.net 2. 접근 방법 시간 제한: 2초 메모리 제한: 128MB 수의 합 구하는 방법 3. 파이썬 코드 S = int(input()) s = S*2 n = int(1) # 무한 반복문으로 제일 높은 n의 값을 찾음 while True: # S*2 < n*(n+1) 한 이유는 1~N 까지 합을구하는 식이 n*(n+1)//2 이기 때문이다. # s 값이 딱나누어 떨어지지 않는 경우 그 값을 딱 초과했을 때 break를 걸어준다. # break 됐을때 count -1 해주는 이유는 값이 한개 더 더해졌기 때문에 빼..
-
11047. [Python]동전 0Python_알고리즘/Silver IV 2023. 1. 30. 21:15
1. 문제 https://www.acmicpc.net/problem/11047 11047번: 동전 0 첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수) www.acmicpc.net 2. 접근 방법 시간 제한: 1초 메모리 제한: 256MB 탐욕 알고리즘(Greedy Algorithm) 3. 파이썬 코드 N,K = map(int,input().split()) # 돈 담을 리스트 생성 money = [] for _ in range(N): money.append(int(input())) cnt = 0 # ..
-
2217. [Python]로프Python_알고리즘/Silver IV 2023. 1. 29. 13:47
1. 문제 https://www.acmicpc.net/problem/2217 2217번: 로프 N(1 ≤ N ≤ 100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하 www.acmicpc.net 2. 접근 방법 시간 제한: 2초 메모리 제한: 192MB 리스트 정렬, 탐색 3. 파이썬 코드 N = int(input()) # 로프 리스트 생성 lope_list = [] for _ in range(N): lope_list.append(int(input())) # 로프 리스트를 큰순으로 정렬함 내림차순(큰거=>작은거) lope_list.sort(reverse=True) # ..