-
Notifications
You must be signed in to change notification settings - Fork 0
[우선순위 큐] 9월 20일 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uC6B0\uC120\uC21C\uC704-\uD050"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include <iostream> | ||
| #include <queue> | ||
|
|
||
| using namespace std; | ||
|
|
||
| struct cmp{ | ||
| bool operator()(int &a, int &b){ | ||
| if(abs(a) != abs(b)) | ||
| return abs(a) > abs(b); | ||
| return a > b; | ||
| } | ||
| }; | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
|
|
||
| priority_queue<int, vector<int>, cmp> pq; | ||
| for(int i=0; i<n; i++){ | ||
| int t; | ||
| cin >> t; | ||
| if(t == 0){ | ||
| if(!pq.empty()) { | ||
| cout << pq.top() << '\n'; | ||
| pq.pop(); | ||
| } | ||
| else | ||
| cout << '0' << '\n'; | ||
| } | ||
| else | ||
| pq.push(t); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() { | ||
|
|
||
| ios::sync_with_stdio(false); | ||
| cin.tie(NULL); | ||
|
|
||
| vector<bool> s(21, false); | ||
|
Comment on lines
+11
to
+12
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 잘 푸셨습니다! 근데 이 배열조차 사용하지 않고 int 변수 하나로 문제를 풀 수 있는 방법도 있어요! |
||
|
|
||
| int n; | ||
| cin >> n; | ||
|
|
||
| string str; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| cin >> str; | ||
| int x; | ||
| if (str == "all") { | ||
| for (int i = 1; i < 21; i++) { | ||
| s[i] = true; | ||
| } | ||
| } else if (str == "empty") { | ||
| for (int i = 1; i < 21; i++) { | ||
| s[i] = false; | ||
| } | ||
| } else if (str == "add") { | ||
| cin >> x; | ||
| if (!s[x]) | ||
| s[x] = true; | ||
| } else if (str == "remove") { | ||
| cin >> x; | ||
| if (s[x]) | ||
| s[x] = false; | ||
| } else if (str == "check") { | ||
| cin >> x; | ||
| if (s[x]) | ||
| cout << '1' << '\n'; | ||
| else | ||
| cout << '0' << '\n'; | ||
|
Comment on lines
+40
to
+43
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도 아래 toggle 처럼 한 출로 나타낼 수 있어요! |
||
| } else { | ||
| cin >> x; | ||
| s[x] = !s[x]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <queue> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n, m; | ||
| cin >> n >> m; | ||
|
|
||
| priority_queue<int, vector<int>, greater<>> least; | ||
| priority_queue<int> temp; | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| int people, limit; | ||
| cin >> people >> limit; | ||
| //신청한 사람이 수강인원보다 작다면 | ||
| if(people < limit){ | ||
| least.push(1); | ||
| for(int j=0; j<people; j++){ | ||
| int t; | ||
| cin >> t; | ||
| } | ||
|
Comment on lines
+20
to
+23
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 중복되니까 밖으로 빼면 어떨까요? |
||
| } | ||
| else{ | ||
| temp = priority_queue<int>(); | ||
| for(int j=0; j<people; j++){ | ||
| int t; | ||
| cin >> t; | ||
| temp.push(t); | ||
| } | ||
| //최소로 배당해야할 마일리지 찾고 입력 | ||
| for(int j=0; j<limit-1; j++){ | ||
| temp.pop(); | ||
| } | ||
| least.push(temp.top()); | ||
| } | ||
| } | ||
|
|
||
| int answer=0, total=0; | ||
| while(total <= m && !least.empty()){ | ||
| total += least.top(); | ||
| least.pop(); | ||
| if(total <= m) | ||
| answer ++; | ||
| } | ||
|
|
||
| cout << answer; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include <iostream> | ||
| #include <queue> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n, m; | ||
| cin >> n >> m; | ||
|
|
||
| priority_queue<long long, vector<long long>, greater<>> q; | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| int t; | ||
| cin >> t; | ||
| q.push(t); | ||
| } | ||
|
|
||
| for(int i=0; i<m; i++){ | ||
| long long a, b; | ||
| a = q.top(); | ||
| q.pop(); | ||
| b = q.top(); | ||
| q.pop(); | ||
| q.push(a+b); | ||
| q.push(a+b); | ||
|
Comment on lines
+19
to
+25
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여긴 중복이 조금 있으니까 반복문으로 처리해도 좋아요! |
||
| } | ||
|
|
||
| long long answer; | ||
| for(int i=0; i<n; i++){ | ||
| answer += q.top(); | ||
| q.pop(); | ||
| } | ||
|
|
||
| cout << answer; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| string from_cpp(int i, string answer, string str){ | ||
|
Comment on lines
+5
to
+6
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 카멜 표기법 사용해주세요~ |
||
| for(int j=i; j<str.length(); j++){ | ||
| char c = str[j]; | ||
| //c++인데 대문자 있으면 에러 | ||
| if('A' <= c && c <= 'Z') | ||
| return "Error!"; | ||
| //_이 연속을 나오면 에러 | ||
| if(c == '_'){ | ||
| if(str[j-1] == '_') | ||
| return "Error!"; | ||
| } | ||
| else{ | ||
| //소문자라면 이전 문자가 _이면 대문자 입력 | ||
| if(str[j-1] == '_') | ||
| answer += toupper(c); | ||
| else | ||
| answer += c; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| string from_java(int i, string answer, string str){ | ||
| for(int j=i; j<str.length(); j++){ | ||
| char c = str[j]; | ||
| //자바인데 _ 입력받으면 에러 | ||
| if(c == '_') | ||
| return "Error!"; | ||
| //대문자이면 _와 소문자 입력 | ||
| if('A' <= c && c <= 'Z'){ | ||
| answer += '_'; | ||
| answer += tolower(c); | ||
| } | ||
| else | ||
| answer += c; | ||
|
Comment on lines
+38
to
+41
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 합칠 수 있는 방법이 있어요~ |
||
| } | ||
| return answer; | ||
| } | ||
|
|
||
| int main(){ | ||
| string str; | ||
| cin >> str; | ||
|
|
||
| string answer = ""; | ||
| //첫글자가 _, 대문자이거나 마지막이 _이면 에러 | ||
| if(str[0] == '_' || ('A' <= str[0] && str[0] <= 'Z') || str[str.length()-1] == '_'){ | ||
| cout << "Error!"; | ||
| return 0; | ||
| } | ||
| else{ | ||
|
Comment on lines
+55
to
+56
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위에 있는 if 문에 걸리면 무조건 리턴하니 이 else는 필요 없어요 |
||
| answer += str[0]; | ||
| } | ||
|
|
||
| for(int i=1; i<str.length(); i++){ | ||
| char c = str[i]; | ||
| if('a' <= c && c <= 'z'){ | ||
| answer += c; | ||
| } | ||
| if(c == '_') { //_을 입력받으면 c++ | ||
| answer = from_cpp(i, answer, str); | ||
| break; | ||
| } | ||
| if('A' <= c && c <= 'Z') { //대문자 입력받으면 java | ||
| answer = from_java(i, answer, str); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| cout << answer; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍