프로그래밍 언어/C++
-
C++ 메모장) 구조체 Vector 특정 요소 찾기 (find_if)프로그래밍 언어/C++ 2021. 4. 26. 17:14
#include #include #include using namespace std; struct cow{ int cow_no; char grade; int profit; }; typedef vector COW; struct Find{ char grade; bool operator()(cow meooo) { return (meooo.grade == grade); } }; cow CREATE_cow(int cow_no, char grade, int profit){ cow c; c.cow_no = cow_no; c.grade = grade; c.profit = profit; return c; } int main(){ COW cows; cows.push_back(CREATE_cow(5,'A',400)); co..
-
C++ 메모장) 구조체 Vector Iterator 사용프로그래밍 언어/C++ 2021. 4. 26. 17:04
#include #include #include using namespace std; struct job{ int job_no; int deadline; int profit; }; typedef vector JOB; job CREATE_job(int job_no, int deadline, int profit){ job j; j.job_no = job_no; j.deadline = deadline; j.profit = profit; return j; } int main(){ int i=0; JOB jobs; jobs.push_back(CREATE_job(1,3,40)); jobs.push_back(CREATE_job(2,2,50)); jobs.push_back(CREATE_job(3,3,20)); jobs..
-
C++ 메모장) Vector 구조체 정렬(sort)프로그래밍 언어/C++ 2021. 4. 26. 16:58
#include #include #include using namespace std; struct job{ int job_no; int deadline; int profit; }; typedef vector JOB; int COMP_BY_DEADLINE(job x, job y){ return x.deadliney.profit; // x가 y보다 더 크도록 정렬 (decreasing order) } int COMP_CUSTOM(job x, job y){ if(x.deadline == y.deadline){ return x.job_no < y.job_no; } return x.deadline