본문 바로가기

전체 글

(18)
[C++] 시간 줄이기 1. ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
[C++] 카운팅 정렬 구현(백준 10989), 시간 초과 문제 #include #define MAX 10001using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, input; int arr[MAX] = { 0 }; cin >> N; for (int i = 0; i > input; arr[input]++; } for (int i = 0; i
[C++] 최대 최소값 구하기 (주의점) 최대, 최소를 이렇게 구할 수 있음.. #include using namespace std;int main() { int input; int number; int min_num = 0; int max_num = 0; bool first = true; cin >> input; for (int i = 0; i > number; if (first == true) { min_num = number; max_num = number; first = false; } if (max_num number) min_num = number; } cout  아래의..
[C++] precision 절대오차, 상대오차 #include using namespace std;int main() { double A, B; cin >> A >> B; cout.precision(10); cout std::cout.precision(10);이 코드 없으면  절대오차 또는 상대오차에 영향 있을 수 있음 std::ios_base::precision - cppreference.com
[C++] printf (string 사용) 주의 #include #include using namespace std;int main() { int input; int result = 1; int output[10] = { 0 }; for (int i = 0; i > input; result *= input; } // printf("result >> %d\n", result); string str = to_string(result); // printf("%s\n", str); // printf 함수는 c 언어 출력 함수로 c++의 std::string 타입을 처리할 수 없음, %s 지정자는 c스타일 문자열(null로 종료되는 'char' 배열)을 생각하고 있음 // 따라서 string 객체를 %s로 출력하려고 하면 메모리 주소를 문자열로 잘못 해석..
[Python] 양방향 연결리스트 구현 class Node: def __init__(self, data): self.data = data self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None self.tail = None def add(self, data): new_node = Node(data) if self.head is None: # 비어있는 노드일 때 self.head = new_node self.tail = new_node #new_node.prev = self.head #new_node.next = self.tail else: # 비어있는 노드가 아닐 때 new_node.prev = self.tail # 1. 새로운 ..
[C++] 오버로딩 1.  반환형은 함수를 구분할 수 있는 기준이 될 수 없다.#include void func1(int n) {}int func1(int n) { int a; return a;}return 0;반환 형식만 다르고 매개변수 목록이 동일하므로, 이러한 형태의 오버로드는 C++에서 허용되지 않는다. 함수를 오버로드하려면 매개변수 목록이 달라야 한다.
[C++] 데이터 입출력 #include int main(void) { int total = 0; int input = 0; for (int i = 0; i > input; total = total + input; } std::cout