코딩테스트/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
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include
위 경로에서 "bits" 폴더 생성 후 "stdc++.h" 파일 넣는다.
#include<bits/stdc++.h>
// include 신경쓰지 않고 코딩에만 집중
int main() {
// logic
}
C++ 온라인 컴파일러 사이트
- https://replit.com/~
- https://www.onlinegdb.com/online_c++_compiler
- https://cpp.sh/
- 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