c++ 5

[자료구조] priority_queue 컨테이너_C++

우선순위 큐(priority_queue) : 큐(Queue)는 먼저 들어오는 데이터가 먼저 나가는 FIFO(First In First Out) 형식의 자료구조이다. 우선순위 큐(Priority Queue)는 먼저 들어오는 데이터가 아니라, 우선순위가 높은 데이터가 먼저 나가는 형태의 자료구조이다. priority_queue 컨테이너 #include templete class priority_queue 🌀 설명 C++ STL에 포함되어 있는 맵를 표현하는 컨테이너. 🌀 인자 T: 자료형 Container: 구현체 Compare: 비교 연산자 🌀 선언 및 초기화 예시 // std::priority_queue mypq; //가장 작은 값이 우선순위가 되는 큐 std::priority_queue mypq; 🌀 ..

CS/자료구조 2022.05.10

[백준] 23057번 : 도전 숫자왕 - C++

문제 https://www.acmicpc.net/problem/23057 23057번: 도전 숫자왕 모든 카드에 적힌 수의 합을 $M$이라고 할 때, 1 이상 $M$ 이하의 자연수 중 만들 수 없는 수의 개수를 출력한다. www.acmicpc.net 설명 #include #include #include #include using namespace std; int card[21]; vector vec; int sum=0; int N; void DFS(int i, int num) { vec.push_back(num); if(i == N) return; DFS(i+1,num+card[i+1]); DFS(i+1,num); } int main() { cin>>N; for(int i = 0;i> card[i]; s..

[C++] 문자열 정리

string 헤더 #include 🌀 선언 및 초기화 예시 //생성과 동시에 초기화 string str1 = "Hello World!"); string str2("Hello World!"); //생성한 후 초기화 string str3; str3 = "Hello World!"; //다른 문자열로 초기화 string str4(str3); 🌀 멤버함수 문자열의 문자 접근 string str = "Hello World!" // 배열처럼 Index로 접근 str[0]; // 'H' 반환. 반환된 문자는 char형 str.at(0); // 'H' 반환. 반환된 문자는 char형 // 맨 앞 문자 반환 str.front(); // 맨 뒤 문자 반환 str.back(); 문자열의 길이 반환 string str = "H..

[백준] 2667번: 단지번호붙이기(BFS) - C++

https://www.acmicpc.net/problem/2667 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net #include #include #include #include using namespace std; int N; int map[25][25]; bool visited[25][25]; int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; queue q; vector v; void reset() { for(int i=0;iN; reset(); for(int i=0;i>s; fo..

[백준] 1012번: 유기농 배추(DFS) - C++

https://www.acmicpc.net/problem/1012 1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net #include #include using namespace std; int M,N,K; int map[50][50]; bool visited[50][50]; int dir[4][2] = {{1,0},{-1,0},{0,-1},{0,1}}; void reset() { for(int y = 0;y>T; for(int i = 0 ;i> M >> N >> K; reset(); for(int k = 0;k>x>>y; ..

반응형