본문 바로가기

전체 글839

C++ ] leetCode 1010 - Pairs of Songs With Total Durations Divisible by 60 리트코드 1010 문제 You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0. Example 1: Input: time = [30,20,150,100,40] Output: 3 Explanation: Three pairs have a total duration divis.. 2024. 4. 24.
인텔 hex 포맷 이해하기 (+ Intel hex to Bin 변환) 인텔 hex 포맷 이해하기 Intel Hex 란? Intel HEX는 ASCII 텍스트 형식으로 이진 정보를 전달하는 파일 형식이다. 주로 MCU의 펌웨어 프로그래밍을 위해 흔히 사용된다. 이 파일 형식은 각 줄이 콜론(:)으로 시작해서 줄바꿈 문자(LF나 CR)로 구분되는 여러줄의 레코드로 구성되며 각 줄은 바이너리 정보를 16진수 ASCII 문자 형태로 담고 있다. 그럼 Intel Hex파일은 Binary파일과 실행파일(.elf 또는 .out)과는 어떻게 다를까? STM32CubeIDE 툴을 사용해서 빌드하면 보통 .elf파일만 생성된다. .elf파일은 Executable and Linkable Format으로 변수 및 함수 심볼 정보, 시스템의 메모리 구조 등 메타데이터를 포함하고 있어 디버거 같은.. 2024. 4. 23.
C++ ] std::set 사용법 std::set STL에 포함되는 std::set은 중복이 없이 정렬된 데이터를 쉽게 관리할 수 있게 해주는 컨테이너로 내부적으로는 균형 이진 검색 트리(레드-블랙 트리)를 사용하여 요소를 저장한다. 가장 큰 특징은 중복을 허용하지 않으므로 모든 요소는 유일하며, 요소를 추가, 삭제, 검색할 때 std::set은 O(log n)을 보장한다. 1. set에 요소 추가하기 set에 요소를 추가할 때는 .insert() 메소드를 사용한다. 삽입 시도 시 중복 요소가 없으면 성공적으로 추가되고, 중복 요소가 있으면 추가되지 않는다. #include #include int main() { std::set mySet; // 요소 추가 mySet.insert(3); mySet.insert(1); mySet.inser.. 2024. 4. 22.
C++ ] leetCode 1029 - Two City Scheduling 리트코드 1029 문제 A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti. Return the minimum cost to fly every person to a city such that exactly n people arrive in each city. Example 1: Input: costs = [[10,20],[30,200],[400,50],[30,20]] Outp.. 2024. 4. 21.
C++ ] leetCode 1418 - Display Table of Food Orders in a Restaurant 리트코드 1418 문제 Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi is the table customer sit at, and foodItemi is the item customer orders. Return the restaurant's “display table”. The “display table” is a table whose row entries.. 2024. 4. 20.
C++ ] std::iota 사용법 처음엔 itoa의 오타인 줄 알았다. std::iota는 헤더에 정의된 C++ 표준 라이브러리 함수로 배열이나 컨테이너에 연속적 숫자를 할당한다. 시작 반복자, 종료 반복자, 그리고 초기 값의 세 개의 매개변수를 받는다. #include #include std::vector v(10); std::iota(v.begin(), v.end(), 0); // v는 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}로 초기화됨 for 반복문을 사용해서 동일한 작업을 수행할 수 있다. 둘 다 O(n) 시간 복잡도를 가지며 유의미한 성능차이는 없을 것 같다. std::vector v(10); for(int i = 0; i < v.size(); ++i) { v[i] = i; } 2024. 4. 19.
C] leetCode 2540 - Minimum Common Value (+ Two Pointers) 리트코드 2540 문제 Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1. Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer. Example 1: Input: nums1 = [1,2,3], nums2 = [2,4] Output: 2 Explanation: T.. 2024. 4. 18.
__DATE__ 에서 필요한 정보를 추출하여 원하는 포맷으로 출력하기 __DATE__, __TIME__ 은 ANSI/ISO 표준으로 정의되고 C 컴파일러 전처리기가 제공하는 특수한 매크로로 소스파일이 컴파일 시점의 날짜와 시간 정보를 나타내는 문자열 리터럴이다. 보통 __TIME__ 의 경우는 우리가 자주 사용하는 형태와 동일하기 때문에 따로 손댈게 없다. 하지만 __DATE__ 의 경우 월, 일, 년도 순이고 월은 영문에 일은 한자리 수 인경우 앞이 공백이여서 그대로 쓰기엔 애매하다. 따라서 __DATE__를 원하는 형태의 formatted string으로 출력하기 위해 다음의 두가지 방법이 있다. 첫번째 방법 yyyy-mm-dd 로 출력하고자 하는 경우 해당 digit Character를 추출해서 조합하는 형태 #include #define BUILD_YEAR_CH0 .. 2024. 4. 17.
C++ ] leetCode 3005 - Count Elements With Maximum Frequency 리트코드 3005 문제 You are given an array nums consisting of positive integers. Return the total frequencies of elements in nums such that those elements all have the maximum frequency. The frequency of an element is the number of occurrences of that element in the array. Example 1: Input: nums = [1,2,2,3,1,4] Output: 4 Explanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequ.. 2024. 4. 16.
Visual Studio ] 코드 정렬 단축키 및 저장 시 자동 정렬 확장 프로그램 현재 문서에서 코드 정렬 Ctrl + K, Ctrl + D 선택 영역 코드 정렬 Ctrl + K, Ctrl + F 확장 > 확장 관리 Format on Save for VS2022 설치 예약 후 Visual Studio를 종료하면 설치 된다. 이후 도구 > 옵션 > Format on Save에서 디테일한 설정을 할 수 있다. 2024. 4. 15.
C++ ] leetCode 1396 - Design Underground System 리트코드 1396번 문제 An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another. Implement the UndergroundSystem class: void checkIn(int id, string stationName, int t) A customer with a card ID equal to id, checks in at the station stationName at time t. A custo.. 2024. 4. 14.
특수 기호 영어로 읽기 ! Exclamation Point ? Question Mark " Quotation Mark # Crosshatch, Sharp $ Dollar Sign % Percent Sign @ At Sign, Commercial At & Ampersand ' Apostrophe * Asterisk - Hyphen, Dash . Period, Full Stop , Comma / Slash \ Back Slash : Colon ; Semicolon ^ Circumflex, Caret ` Grave { Left Brace } Right Brace [ Left Bracket ] Right Bracket ( Left Parenthesis ) Right Parenthesis | Vertical Bar ~ Tilde _ U.. 2024. 4. 13.
도로교통법 위반차량 신고하기 (안전신문고) 원래 교통법규 위반사항은 그동안 스마트국민제보, 안전신문고 두 가지 채널로 신고할 수 있었는데 2024년 4월부로 스마트국민제보 웹, 앱은 운영 중단되고 안전신문고로 통합 운영될 예정이니 앞으로는 안전신문고를 통해 신고해야한다.  신고방법안전신문고 > 자동차, 교통위반 > 유형선택에서 교통위반(고속도로 포함) 선택 블랙박스 영상 첨부하고 발생지역, 식별한 위반차량의 차량번호, 발생일자와 발생시각을 입력하여 신고하면 된다.    유형선택을 클릭하면 대표적인 위반 사례를 볼 수 있고, 신고 후 민원처리까지 보통 2주의 시간이 걸린다. 2024. 4. 12.
Excitation Excitation Excitation은 영어로 자극, 흥분이란 뜻으로 발전기나 모터 시스템에 대해 설명할 때 자주 등장하는 용어이지만 다양한 센서나 측정 장비에서도 사용되는 중요한 개념이다. 발전기나 모터 시스템에서 Excitation은 권선(코일)에 전류를 흘려서 자기장을 생성하는 데 필요한 전류나 전압을 의미한다. 반면, 센서나 측정 장비에서의 Excitation은 해당 센서를 구동하여 출력신호를 만들어내기 위해 필요한 외부 전원을 뜻한다. 보통 스트레인 게이지, 서미스터 등 능동형 센서들이 물리적 변화량을 전기적 신호로 변환하기 위해 외부에서 제공되는 Excitation power를 사용하는데, 미세한 물리적 변화를 감지하여 변환된 전기 신호는 보통 mV 단위의 비교적 작은 스케일로 출력되는 경우.. 2024. 4. 11.
TMS320F28388D ] 부트핀 구성을 바꾸는 법 & SCI boot 모드 사용시 디폴트 TX/RX핀 말고 다른 핀을 사용하는 방법 TRM에서 부트핀 구성을 바꾸는 방법과 SCI boot 모드 사용시 디폴트 TX/RX핀 말고 다른 핀을 사용하는 방법을 확인해보자.   CPU의 Boot 프로세스 TRM의 Boot flow를 살펴보면 디버거가 연결되어 있느냐에 따라 두가지 종류의 Boot가 있다. Standalone BootEmulation Boot       Emulation Boot 프로세스 먼저 Emulation Boot 일 때는 살펴보면 EMUBOOTPINCONFIG를 읽어 정의된 행동을 하도록 되어있다.       Standalone Boot 프로세스 그리고 Standalone Boot인 경우에는 Zx-BOOTPINCONFIG, Zx-BOOTDEF를 읽도록 되어있는데 부트핀 구성 정보에는 Z2와 Z1 두 그룹이 있다.Z2가 Z1.. 2024. 4. 10.
C++ ] leetCode 1249 - Minimum Remove to Make Valid Parentheses 리트코드 1249번 문제 Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: It is the empty string, contains only lowercase characters, or It can be written as AB (A conca.. 2024. 4. 9.
하남 벚꽃 명소, 하남 스타필드 옆 당정뜰, 주차 정보 지도에 표시한 곳이 벚꽃 명소이며 주차는 걸어서 5~10분 거리인 하남 스타필드에 무료로 할 수 있다. 2024. 4. 8.
2의 거듭제곱에 대한 나머지 연산 최적화 및 bit mask 생성 2의 거듭제곱으로 나머지 연산을 수행할 때는 % 연산자 대신 비트 연산을 사용해 연산속도를 최적화할 수 있다. 예를 들어, 어떤 수 x에 대해 x % 8 의 결과를 구하고 싶다면, x를 7과 비트 단위로 AND 연산하는 것과 결과가 같으므로 x & 7 으로 대체할 수 있다. 예시. #include #define BUFSIZE 8 int main() { int x = 10; int result = x & (BUFSIZE - 1); printf("Result: %d\n", result); return 0; } 위와 같이 알아내고자 하는 bit를 전부 1로 셋하고 & 연산으로 값을 추출하는 것은 비트 마스크기법이다. 관련글을 쓴 김에 mask를 생성하고 사용하는 방법에 대해 좀 더 글을 써보겠다. 펌웨어 프로.. 2024. 4. 8.
C++ ] leetCode 861 - Score After Flipping Matrix 리트코드 861 문제 You are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's). Every row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers. Return the highest possible score after making any number of moves (including zero.. 2024. 4. 6.
Windows 명령 프롬프트에서 리다이렉션과 파이프 사용 리다이렉션 리다이렉션이란 표준입력과 표준출력의 방향을 키보드와 모니터가 아닌 다른곳으로 바꾸어주는 것을 말한다. 주로 명령어의 출력을 터미널 창이 아닌 파일로 보내거나, 파일의 내용을 명령어의 입력으로 사용할 때 쓰인다. 기본적인 리다이렉션 심볼에는 (출력 리다이렉션), >> (출력을 파일에 추가)가 있다. sort명령어를 사용해 직접 테스트해보자. 윈도우의 sort 명령은 텍스트를 행단위로 정렬할 때 사용하는 명령어이다. 다음과 같은 테스트 파일을 만든다. beforeSort.txt 123 456 789 123 456 789 - 입력 리다이렉션 sort < beforeSort.txt beforeSort.txt 파일의 내용을 sort 명령어의 입력으로 사용한다. 즉, 파일을 .. 2024. 4. 4.
C++ ] leetCode 2596 - Check Knight Tour Configuration 리트코드 2596번 문제 There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once. You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]th cell that the knight visited. .. 2024. 4. 2.
UTP 케이블의 종류 및 RJ-45 pinout UTP 케이블 일반적으로 우리가 부르는 랜케이블이라고 부르는 이더넷 통신에 사용되는 UTP(Unshielded Twisted Pair) 케이블은 두가닥씩 꼬여진 4쌍의 총 8가닥의 전선으로 이루어져 있고 말단에는 RJ-45 커넥터가 달려 네트워크 장비를 연결하는데 사용된다. 전선은 단색과 줄무늬색으로 구성되어있고 같은 색 쌍은 차동신호로 TX/RX 데이터 전송해 쓰인다. 10BASE-T와 100BASE-T 이더넷 표준에서 UTP 케이블의 8선 중 1, 2, 3, 6번 핀 4선만 사용해 데이터 전송을 처리했고, 1000BASE-T(Gigabit Ethernet) 또는 그 이상의 속도를 지원하는 네트워크 표준에서는 8개의 선을 모두 사용해 통신한다. RJ45 Pinout UTP 케이블을 클림핑할 때 사용되는.. 2024. 3. 28.
C++ ] leetCode 150 - Evaluate Reverse Polish Notation You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The valid operators are '+', '-', '*', and '/'. Each operand may be an integer or another expression. The division between two integers always truncates toward zero. There will not be any.. 2024. 3. 27.
글꼴 삭제하기 (feat. Ligature) 설치한 글꼴은 C:\Windows\Fonts 폴더에 저장되므로 해당 위치에서 삭제할 글꼴을 찾아 우클릭으로 삭제하면 된다. D2Coding 글꼴을 깔았는데 모르고 Ligature 버전을 설치해서 삭제하고 다시 설치해야 했다. Ligature는 >=, ==, != 같은 기호를 아래와 같이 보여주는데 개인적으로 그냥 일반버전인 나은 것 같다. 일반 D2Coding 폴더에 들어가면 ttf와 ttc파일이 있고 ttc는 여러 ttf가 합쳐진 파일인데 나는 Bold체는 안쓰는 편이라 그냥 D2Coding ttf 파일로 설치했다. 2024. 3. 26.
Text to ASCII Art 사이트 위 그림처럼 ASCII를 사용해 텍스트나 그림을 표현하는 걸 ASCII 아트라고 하는데 텍스트를 입력하면 ASCII 아트를 자동 생성해주는 사이트가 있어 소개한다. https://www.asciiart.eu/text-to-ascii-art ASCII Art Archive A large collection of ASCII art drawings and other related ASCII art pictures. www.asciiart.eu 3D - 3D ASCII _________ _______ ________ _________ |\___ ___\\ ___ \ |\ ____\|\___ ___\ \|___ \ \_\ \ __/|\ \ \___|\|___ \ \_| \ \ \ \ \ \_|/_\ \_____ .. 2024. 3. 24.
C++ ] leetCode 739 - Daily Temperatures 리트코드 739번 문제 Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead. Example 1: Input: temperatures = [73,74,75,71,69,72,76,73] Output: [1,1,4,2,1,1,0,0] Example 2: In.. 2024. 3. 22.
C++ ] std::stack 사용법 C++의 std::stack은 STL(Standard Template Library)의 일부로 후입선출(LIFO: Last In, First Out) 방식을 따르는 자료구조이며 데이터의 삽입(push)과 삭제(pop)가 한 쪽 끝에서만 이루어지는 특징을 가지고 있다. 1. stack 헤더 파일 포함 #include 2. stack 객체 생성 std::stack myStack; 3. 요소 삽입 (push) myStack.push(10); 4. 요소 제거 (pop) myStack.pop(); 5. 최상위 요소 접근 (top) std::cout 2024. 3. 20.
C++ ] leetCode 2136 - Earliest Possible Day of Full Bloom 리트코드 2136 문제 You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each: plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not.. 2024. 3. 18.
USB 2.0 pin out + ID핀 역할 제목은 USB 2.0 pinout으로 했지만 USB 1.0 부터 USB 2.0 표준에서의 Type-A 및 Type-B 커넥터의 핀 구성은 사실 동일하다. Type-A 커넥터는 +5V VCC, 차동신호 데이터 라인 2개(D-, D-), GND 총 4개의 핀을 사용한다. 그리고 Type-B Mini, Type-B Micro 커넥터는 ID핀이 추가되서 총 5개의 핀을 사용하는데 이 핀은 USB OTG(On-The-Go)기능을 지원하기 위해 사용된다. ✔ OTG란? USB는 USB 컨트롤러가 존재하는 호스트와 그 반대인 게스트라는 개념이 있는데 일반인들이 호스트와 게스트 개념을 몰라도 연결 방향을 실수하지 않도록 호스트(PC)에는 Type-A 단자를 달고 주변기기(프린터, 디카, 스마트폰)에는 Type-B단자를.. 2024. 3. 16.
C++ ] leetCode 6 - Zigzag Conversion leetCode 6번 문제 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)And then read line by line: "PAHNAPLSIIGYIR"Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows);  Example 1: Input: s = "PAYPALISHIRING",.. 2024. 3. 14.