분류 전체보기 (308) 썸네일형 리스트형 [백준] 10989번 - 카운팅 정렬 #include #include #include using namespace std; int main() { int count,a; cin >> count; int arr[10001] = { 0 }; for (int i = 1; i > a; arr[a]++; } for (int i = 1; i < 10001;i++) { if (arr[i] != 0) { for (int j = 0; j < arr[i]; j++) { cout [C++] cin,cout,endl 계산속도 올리기(시간 초과 해결) std::endl은 \n보다 느리다. endl는 개행하는 것과 동시에 내부 버퍼를 비우는 역할을 하기 때문에 시간 초과가 난다면 endl 보다 \n을 이용해보자. ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin과 cout계산 속도 높여주는 코드 [백준] 2750번 - 선택정렬,버블정렬,삽입정렬 #include #include #include #include using namespace std; int main() { int count; cin >> count; int* num = new int[count]; for (int i = 0; i > a; num[i] = a; } int minidx,temp; for (int i = 0; i num[j]) { min = num[j]; minidx = j; } } if (minidx != 0) { temp = num[i]; num[i] = num[min.. [백준] 11729번 하노이 탑 - 재귀 알고리즘 문제풀이 영상 https://www.youtube.com/watch?v=AogMbfRwguk 이동횟수 식 유도 및 문제풀이 https://st-lab.tistory.com/96 [백준] 11729번 : 하노이 탑 이동 순서 - JAVA [자바] www.acmicpc.net/problem/11729 11729번: 하노이 탑 이동 순서 세 개의 장대가 있고 첫 번째 장대에는 반경이 서로 다른 n개의 원판이 쌓여 있다. 각 원판은 반경이 큰 순서대로 쌓여있다. 이제 수도승들이 st-lab.tistory.com 너무 어렵다.. [C++] 범위 기반 for문(range based for statement) 범위 기반 for문은 C++11에서 추가되었는데, 배열 및 컨테이너에서 사용가능하며 기본 문법은 for ( Type elem : Container ) 이다. int a[5] = {1,2,3,4,5}; for( int i : a ){ cout [프로그래머스] Lv1. 신규 아이디 추천 - 반복자 활용 #include #include using namespace std; string solution(string new_id) { for (string::iterator iter = new_id.begin(); iter != new_id.end();) { if (*iter >= 65 && *iter = 0 && *iter = 58 && *iter = 91 && *iter = 123) iter = new_id.erase(iter); else ++iter; } for (string::iterator iter = new_id.begin(); iter != new_id.end();) { if (iter != new_id.begin()) { string::iterator prevIter = prev(iter); i.. [C++] this는 포인터다 class Simple { private: int value; public: Simple(int avalue) : value(avalue) { } void OutValue() { printf("value=%d\n",value); } }; void main() { Simple A(1), B(2); A.OutValue(); B.OutValue(); } main에서 OutputValue()는 매개변수가 없는데 어떻게 A인지 B인지 알고 value값을 출력할까? 그것은 사실 위 설명처럼 함수 앞의 객체의 포인터를 매개변수로 받고 있기 때문이다. OutputValue는 매개변수가 빈 것 처럼 보이지만 Simple * const 타입의 this를 매개변수로 받는 것이다. Simple *FindBig(Simple *.. [C++] 포인터와 레퍼런스의 차이 int value = 5; int* const ptr = &value; int& ref = value; 포인터 변수 ptr과 참조형 변수 ref는 같은 의미를 가진다. *ptr = 5; ref = 5; 위 명령문들 역시 같은 효과를 낸다. 포인터는 메모리 주소를 할당하고 참조형 변수는 대상 자체를 할당한다. value 와 ref는 동일한 메모리를 참조하므로 참조형 변수 ref가 value의 별명이라고 할 수 있다. 그 외 Reference는 NULL 값을 넣지 못하는 등 포인터와 다른점이 있는데 메모리 주소 값에 직접 접근할 필요가 없는 이상 Reference(참조형) 변수를 쓰는 것이 안전하고 좋다. 이전 1 ··· 34 35 36 37 38 39 다음