Eat Study Love

먹고 공부하고 사랑하라

daily code 20

SSSP(Single Source Shortest Path) / APSP(All-Pairs Shortest Path) 실습

Algorithm의 대명사인 Shortest Path와 관련된 실습이다.SSSP / APSP를 구현해보는 실습을 할 것이다. 대표적으로 FloydWarshall과 BellmanFord 알고리즘을 확인해보자. 실습자료는 위와 같다.#include #include #include #include // 아래 header는 내가 추가#include using namespace std;/*//////////////////////// Description ////////////////////////////There are n cities in a logistics network, numbered from 0 to n−1. The edges array represents the logistics routes bet..

C++ function implementation(feat, priority queue & DP)

이번 실습의 주제는 C++ Function Implementation이다.실습의 목표는 아래와 같다.  애증의 DP문제의 경우, 이해가 좀 어려운데 주석과 아래 예시를 보면 그래도 좀 느낌이 온다. 근데 문제는 이 느낌이 항상 답지를 보고 나서야 온다는 것-_-..문제 풀기 전부터 이 느낌이 머리에 딱 꽂치는 사람은 진짜 프로그래밍 고수다. 분명허다!! 나머지 문제는 Priority queue를 이용해 풀면 쉽다. 코드는 아래에 공유#include #include #include #include #include // 내가 추가using namespace std; // 내가 추가#include struct ListNode { int val; ListNod..

Type Casting & Exception Handling + OOP 실습

C++을 이용해서 Type Casting 과 Exception Handling을 해보겠다. Type Casting이란 특정 Variable을 다른 data type으로 변화시키는 것이며 종류로는 1. C-style Casting2. Static cast3. Dynamic cast4. Const cast5. Reinterpret cast 이렇게 다섯가지 정도를 알아보자.Elec* elec = new pikachu();Fire* char = (Fire*)elec;// Compile error는 없지만 ERROR static_cast 으로 compile time에 casting을 걸어버려서 깔끔하다.  Exception Handling은 Try - Catch 구문이다.일단 try 안쪽에 있는 구문을 실행해보고..

Permutations(Array,Backtracking)

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1:Input: nums = [1,2,3]Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]Example 2:Input: nums = [0,1]Output: [[0,1],[1,0]]Example 3:Input: nums = [1]Output: [[1]] Constraints:1 -10 All the integers of nums are unique.뭔가 기본적인 컨셉의 문제인데, 이게 또 한 번쯤은 집고 넘어가줘야 찝찝한게 없다..

Coding_Practice 2025.02.10

VS code C++ Debugging & Operator overloading

이번엔, C++ 코딩을 하며 자주 마주하는 디버깅의 현장을 살펴보겠다. 관련자료는 아래와 같다.  용량이 크진 않으니 VS Code를 통해 C++ 코딩 작업을 할 경우, 잘 참고해서 하면 되겠다. 기본적으로 디버깅할땐 print문을 통해서 디버깅하는 방법이 있고, VS Code 상의 Debug Extention을 이용하는 방법이 있다. 전자는 직관적이지만, 귀찮고 후자는 효과적이지만 방법을 터득하기가 귀찮다. 일단 간단하게 Debugging 실습을 진행해보자. #include #include using namespace std;int main(){ list lst = {1,2,3,4,5}; // i want to practice using pop_back function in list! ..

Maximum Employees to Be Invited to a Meeting(Depth-First Search,Graph,Topological Sort)

https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting/description/?envType=daily-question&envId=2025-01-26A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees.The employees are numbered from 0 to n - 1. Each employee has a favorite person and they will..

Coding_Practice 2025.01.26