250x250
Notice
Recent Posts
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
관리 메뉴

일상 코딩

[C++/CPP] C++ 코딩테스트용 set() 본문

코딩테스트/inflearn C++ 코딩테스트

[C++/CPP] C++ 코딩테스트용 set()

polarcompass 2023. 12. 28. 22:29
728x90
Visual Studio에 <bits/stdc++.h> 헤더파일 추가하기

출처:https://hkhan.tistory.com/36

 

[C++] Visual Studio에 <bits/stdc++.h> 헤더파일 추가하기

알고리즘 문제를 풀 때, 필요한 헤더 파일들을 매번 include 해주는 과정이 귀찮게 느껴질 수 있다. 자주 쓰이는 헤더 파일들을 담은 stdc++.h 파일을 다운로드 받은 후, 코드 컴파일러의 include 파일

hkhan.tistory.com

stdc++.h
0.00MB

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include

위 경로에서 " 14.33 .31629 "는 Visual Studio 버전이며 각자 다른 숫자일 수 있으니 불안하다면 각 폴더에 있는 include에 bits 폴더 복사 후 붙여넣기 해준다.

위 경로에서 "bits" 폴더 생성 후 "stdc++.h" 파일 넣는다.

#include<bits/stdc++.h>
// include 신경쓰지 않고 코딩에만 집중

int main() {
	// logic
}

 

C++ 온라인 컴파일러 사이트
  1. https://replit.com/~
  2. https://www.onlinegdb.com/online_c++_compiler
  3. https://cpp.sh/
  4. https://www.tutorialspoint.com/compile_cpp_online.php
1. set()
#include <set>
#include <vector>
#include <iostream>

int main() {
  // 인수 목록을 선언합니다.
  std::vector<int> args = {1, 2, 3, 1, 2, 3};

  // 인수 목록을 std::set으로 변환합니다.
  std::set<int> unique_args(args.begin(), args.end());

  // 중복된 인수를 제거한 인수 목록을 출력합니다.
  for (const auto& arg : unique_args) {
    std::cout << arg << std::endl;
  }
}
// 출력 결과
1
2
3

 

2. unordered_set()
#include <unordered_set>
#include <iostream>

int main() {
  // 인수 목록을 선언합니다.
  std::vector<int> args = {1, 2, 3, 1, 2, 3};

  // 인수 목록을 std::unordered_set으로 변환합니다.
  std::unordered_set<int> unique_args(args.begin(), args.end());

  // 중복된 인수를 제거한 인수 목록을 출력합니다.
  for (const auto& arg : unique_args) {
    std::cout << arg << std::endl;
  }
}
// 출력 결과
1
2
3

 

std::set()std::unordered_set()과 유사한 기능을 제공하지만, 

std::unordered_set()과 달리 인수의 순서를 유지합니다. 

따라서 중복된 인수를 제거하는 용도뿐만 아니라 인수의 순서를 유지해야 하는 용도로도 std::set()을 사용할 수 있습니다.

728x90