C++

    C++ 클래스 배열 포인터 및 2차원 배열 포인터

    클래스 포인터 배열은 아래와 같다. #include #include #define SIZE 3 using namespace std; class A { int mVal = 0; public: // 생성자 A() { cout

    [골4] 15683 - 감시

    https://github.com/encrypted-def/BOJ/blob/master/15683.cpp 아래는 내 코드다 cctv가 1일 때에 대비해서 풀지 못했다. #include #include #include using namespace std; using IntPair = pair; #define MAX_SIZE 100 #define y first #define x second int map[MAX_SIZE][MAX_SIZE]{ 0 }; int tmpMap[MAX_SIZE][MAX_SIZE]{ 0 }; int h, w; // CCTV 위치 저장용도 vector vC; // 다음 위치 시계 방향 IntPair pos[] { { 1, 0 }, // 북 { 0, 1 }, // 서 {-1, 0 }, /..

    [골5] 9663 - N-Queen

    #include using namespace std; int n, answer = 0; int vis[15]{ 0 }; // 유망한지 체크 bool Check(int cnt) { for (int i = 0; i < cnt; i++) { auto vis1 = vis[cnt], vis2 = vis[i]; if (vis1 == vis2 || cnt - i == abs(vis1 - vis2)) return 0; } return 1; } void BackTracking(int cnt) { if (cnt == n) { answer++; return; } for (int i = 0; i < n; i++) { vis[cnt] = i; if (Check(cnt)) BackTracking(cnt + 1); } } int ..

    C++ 간단하게 사용할 수 있는 포인터 해제 매크로 함수

    #include using namespace std; #define SAFETY_CHECK(ptr) \ { \ if (ptr == nullptr) \ { \ cout

    [실3] 1966 - 프린터 큐

    #include #include #include #include using namespace std; #define y front().first #define x front().second int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int tc; cin >> tc; for (int i = 0; i > t >> f; queue q; priority_queue pq; for (int j = 0; j > val; q.push({ j,val }); pq.push(val); } ..

    [실3] 1021 - 회전하는 큐

    #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int s, n, cnt = 0; cin >> s >> n; deque dq; for (int i = 1; i > num; for (int i = 0; i < s; i++) { if (dq[i] == num) { idx = i; break; } } for (int i = 0; i < dq.size(); i++) { if (dq.front() == num) { dq.pop_front(); break; } if (idx < dq.size() / 2 + 1) { dq.push_back(dq..

    [골5] 2023 - 신기한 소수

    #include #include #include #include using namespace std; int n = 0; bool Prime(int num) { for (int i = 2; i * i

    [골2] 10800 - 컬러볼

    #include #include #include #include using namespace std; struct sColorBall { int n, color, size; sColorBall() = default; sColorBall(int n, int color, int size):n(n),color(color),size(size) { } }; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector vecBall(n); for (int i = 0; i > vecBall[i].color >> vecBall[i].size; } sort(vecB..

    C++ 포인터 객체 자살 (delete this)

    delete this는 소멸자에 해선 안되고 또한 매우 안좋은 코딩 스타일이다. 사용하고자 하면 몇가지 주의 사항이 있다. new로만 인스턴스화가 되있어야 한다 (new[] X), 다른 포인터를 가리킨다던가, 레퍼런스를 가리켜서는 안된다. 맨 마지막 구문이여야 한다. 멤버 변수 변경 또는 함수 호출해선 안된다. this 오브젝트를 해제 후 건드려선 안된다, 역참조, -> 참조, 비교 등. class A { public: void fun() { delete this; } }; int main() { /* 실행 가능 */ A *ptr = new A; ptr->fun(); ptr = NULL; /* 에러 : Undefined Behavior */ A a; a.fun(); getchar(); return 0; ..

    [Unreal] 사용자 정의 컴포넌트 (UActorComponent)

    생성 방법은 간단하다, C++ 클래스 생성 > Actor Component를 선택한다. 아래와 같이 함수들이 기본으로 설정될텐데 처음 보는 것들이다. 엑터일 시 PrimaryActorTick.bCanEverTick = true; 이지만 엑터 컴포넌트 일땐 PrimaryComponentTick.bCanEverTick = true; 이다. BeginPlay 함수는 동일하다 Tick 함수 대신 TickComponent 함수이다. 사용 조건은 간단한데 다른 컴포넌트가 들어가면 안된다 즉 데이터 들고있는 용도 또는 오버라이딩을 하여 여러군데에 같은 함수를 선언하는걸 방지용으로만 생각하면 된다. HP Comp에서 저런 형태가 나오는게 정상이다 만약에 헤더파일에 다른 기타 컴포넌트를 선언할 시 BeginPlay 함수..