목록전체 글 (103)
배움 저장소

이 글에서는 left shift와 right shift 연산이 어떤 차이가 있는지 다룬다. 이러한 차이가 코드에서 예기치 못한 상황을 만들 수 있다. left shift와 right shift 연산의 차이를 알아보자. 1. signed && 음수 signed값은 맨 앞 bit가 양수 / 음수를 나타낸다. 위 값은 음수이므로 >> 연산자를 사용할 때 부호 값은 그대로 유지된다. 2. unsigned || signed && 양수 위 상황은 unsgined 타입이거나 signed 타입일 경우 양수 값을 가질 때이다. 이 때 >> 연산자를 사용하면 부호 값은 계산되지 않는다. 따라서 다음과 같은 상황을 이해할 수 있다. char x = CHAR_MAX; printf("%i\n", x); // => 127 cha..
https://leetcode.com/problems/subsets/ Subsets - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Backtracking class Solution { public: vector subsets(vector& nums) { backtracking(nums, 0); return result; } private: vector result; vector saved; void backtracking(vector& nums, int..
https://leetcode.com/problems/unique-paths/ Unique Paths - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. DFS풀이 ( 시간초과 ) class Solution { public: int uniquePaths(int m, int n) { result = 0; max_y = m-1; max_x = n-1; DFS(0,0); return result; } private: int result, max_y, max_x; ..

4.1 문자열 입출력하기 char fruit; char fruit2[40]; /* char type 40개 저장공간을 확보 */ scanf("%c", &fruit); scanf("%s", fruit2); /* 이때 fruit2는 char type 40개 저장공간의 첫 번째를 가리키는 포인트다. 따라서 & 연산자를 사용할 필요가 없다.*/ printf("%c", fruit); printf("%s", fruit2); // 사용공간을 지정해주지 않고 초기화 가능하다 // 자리 계산은 알아서 해준다 char fruit3[] = "banana"; 4.2 sizeof 연산자 1) sizeof basic types int i = 0; unsigned int int_size1 = sizeof i; unsigned in..
3.10 문자형 #include int main() { char c = 'A'; char d = 65; printf("%c %hhd\n", c,c); // -> A 65 printf("%c %hhd\n", d,d); // -> A 65 printf("%c %hhd\n", ',d); // -> A 65 printf("%c %hhd\n", d,d); // -> A 65 printf("\a"); // -> beef alarm printf("\07"); // -> 8진수 7 ( character 'a'와 동일) printf("\x7"); // -> 16진수 7 float salary; printf("$______\b\b\b\b\b\b");// $____ scanf("%f", &salary); // ^ 해당 위치..
더보기 이 글은 다음 문서를 읽고 공부한 글입니다. 틀린 내용이 있다면 알려주세요 Introduction to C++ Programming in UE4 Introductory guide for C++ programmers new to Unreal Engine docs.unrealengine.com 1. UPROPERTY( Transient ) Transient 개념이 생소하다. UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category="Damage") Transient로 설정된 변수는 값을 디스크에 저장하지 않는다. 따로 바이너리로 만들어 디스크에 저장해 쓸데없는 낭비가 일어날 수 있는데, 그걸 막는다는 뜻이다. "이 값은 초기값 없이 다른 변..
https://leetcode.com/problems/combination-sum/ Combination Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Backtracking 사용 한 번 정리한 코드. 처음엔 Set을 사용했다. for문을 돌 때 현재 층(index)부터 시작하면 중복되는 경우의 수를 탐색하지 않아 Set을 사용할 필요가 없다. class Solution { public: vector combinationSum(vector& ca..
1. unique_ptr 여러 포인터가 하나의 대상을 가르키는 걸 방지해준다. 해당 값을 가리키는 ptr를 한 개로 제한하고 싶을때 사용하면 된다. 만약 여러 unique_ptr이 하나의 대상을 가르키면 컴파일 에러가 난다. 특정 데이터의 소유권을 다른 unique_ptr로 옮기려면 move()함수를 이용하자 unique_ptr ptr1 (new A); // Error: can't copy unique_ptr unique_ptr ptr2 = ptr1; // Works, resource now stored in ptr2 unique_ptr ptr2 = move(ptr1); 예제 // C++ program to illustrate the use of unique_ptr #include #include usi..