-
Notifications
You must be signed in to change notification settings - Fork 0
[맵, 셋] 9월 12일 #2
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: "\uB9F5,-\uC14B"
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,61 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| string a; | ||
| string b; | ||
|
|
||
| cin >> a >> b; | ||
|
|
||
| //자릿수 큰 수가 a | ||
| if(a.length() < b.length()){ | ||
| swap(a, b); | ||
| } | ||
|
|
||
| int a_len = a.length(); | ||
| int b_len = b.length(); | ||
| int sum = 0; | ||
| int carry = 0; | ||
| vector<int> res(a_len+1, {}) ; | ||
|
|
||
| //b의 가장 높은 자릿수까지 덧셈하기 | ||
| while(b_len > 0){ | ||
| sum = a[a_len-1]-'0' + b[b_len-1]-'0' + carry; | ||
|
|
||
| if(sum > 9){ | ||
| sum -= 10; | ||
| carry = 1; | ||
| } | ||
| else | ||
| carry = 0; | ||
| res[a_len] = sum; | ||
| a_len--; | ||
| b_len--; | ||
| } | ||
|
|
||
| //a의 가장 높은 자릿수까지 덧셈하기 | ||
| while(a_len>0){ | ||
| sum = a[a_len-1]-'0' + carry; | ||
| if(sum>9){ | ||
| sum -= 10; | ||
| carry = 1; | ||
| } | ||
| else | ||
| carry = 0; | ||
| res[a_len] = sum; | ||
| a_len--; | ||
| } | ||
|
|
||
| //출력 | ||
| if(carry !=0) { //마지막에 반올림된 수가 있을 때 | ||
| res[0] = carry; | ||
| for (int i = 0; i <= a.length(); i++) | ||
| cout << res[i]; | ||
| } | ||
| else{ | ||
| for(int i = 1; i <= a.length(); i++) | ||
| cout << res[i]; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <set> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n, m, cnt; | ||
| set<string> s; | ||
| cin >> n >> m; | ||
|
|
||
| string a; | ||
| for(int i=0; i<n; i++){ | ||
|
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. n, m 은 다시 쓰지 않으니 while(n--) 으로 입력 받아도 좋을 것 같아요~! |
||
| cin >> a; | ||
| s.insert(a); | ||
| } | ||
|
|
||
| for(int i=0; i<m; i++){ | ||
| cin >> a; | ||
| if(s.find(a) != s.end()) | ||
| cnt++; | ||
| } | ||
|
|
||
| cout << cnt; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <set> | ||
|
|
||
| using namespace std; | ||
| int main(){ | ||
| int lis_num, see_num, cnt=0; | ||
| string s; | ||
| set<string> ans; | ||
| cin >> lis_num >> see_num; | ||
|
|
||
| set<string> listen; | ||
|
|
||
| //듣지 못한 사람 입력 | ||
| for(int i=0; i<lis_num; i++){ | ||
| cin >> s; | ||
| listen.insert(s); | ||
| } | ||
|
|
||
| //보지 못한 사람 중 듣지도 못한 사람 찾기 | ||
| for(int i=0; i<see_num; i++){ | ||
| cin >> s; | ||
| if(listen.find(s) != listen.end()){ | ||
| ans.insert(s); | ||
| cnt++; | ||
| } | ||
| } | ||
|
|
||
| //출력 | ||
| cout << cnt << '\n'; | ||
|
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. cnt 변수 사용도 좋지만, ans 만으로도 크기를 알 수 있는 방법이 있죠! |
||
| for(auto iter = ans.begin(); iter != ans.end(); iter++){ | ||
| cout << *iter << '\n'; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #include <iostream> | ||
| #include <cstdlib> | ||
|
|
||
| using namespace std; | ||
|
|
||
| //음수를 2로 나눈 몫 | ||
| int divideByTwo(int num){ | ||
| int q = 0; | ||
| while(2*q-num > 0) | ||
| q--; | ||
| return q; | ||
| } | ||
|
Comment on lines
+6
to
+12
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. p2. 음수를 2로 나눈 몫을 잘 처리해주셨어요! 하지만 반복문의 사용 없이 한 번의 연산 만으로 처리할 수 있는 방법이 있어요. -5/2를 하면 -3이 나와야 하는데, c++에선 -2가 나오죠! 어떻게 하면 좋을까요? 아니면 floor 함수에 대해 알아봐도 좋을 것 같아요. |
||
|
|
||
| // 기초 대사량 변화 고려하지 않았을 때 체중 | ||
| int Weight(int weight, int eat_before, int day, int eat_after, int move){ | ||
| weight -= abs(eat_after-(eat_before + move))*day; | ||
| return weight; | ||
| } | ||
|
|
||
| // 기초 대사량 변화 고려했을 때 체중 | ||
| int realWeight(int weight, int &eat_change, int day, int limit, int eat_after, int move){ | ||
| for(int i=0; i<day; i++){ | ||
| int decrease = eat_after-(eat_change + move); | ||
| weight += decrease; | ||
| if(abs(decrease) > limit) { | ||
| eat_change += divideByTwo(decrease); | ||
| } | ||
| } | ||
| return weight; | ||
| } | ||
|
|
||
|
|
||
| int main() { | ||
| int weight, eat_before, limit, day, eat_after, move, eat_change; | ||
| cin >> weight >> eat_before >> limit >> day >> eat_after >> move; | ||
| eat_change = eat_before; | ||
|
|
||
| //기초대사량을 고려하지 않은 체중 출력 | ||
| int weight1 = Weight(weight, eat_before, day, eat_after, move); | ||
| if(weight1 > 0){ | ||
| cout << weight1 << ' ' << eat_before << '\n'; | ||
| } | ||
| else | ||
| cout << "Danger Diet" << '\n'; | ||
|
|
||
| //기초대사량을 고려한 체중 출력 | ||
| int weight2 = realWeight(weight, eat_change, day, limit, eat_after, move); | ||
| if(weight2 > 0 && eat_change > 0){ | ||
| cout << weight2 << ' ' << eat_change << ' '; | ||
| if(eat_change < eat_before) | ||
| cout << "YOYO"; | ||
| else | ||
| cout << "NO"; | ||
| } | ||
| else | ||
| cout << "Danger Diet"; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // | ||
| // Created by LG on 2021-09-12. | ||
| // | ||
|
|
||
|
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. 앗 4385 문제는 아직 못 푸신 걸까요..!? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <map> | ||
|
|
||
| using namespace std; | ||
| int main(){ | ||
| int t; | ||
| cin >> t; | ||
|
|
||
| for(int i=0; i<t; i++){ | ||
| int n, ans=1; | ||
| string name, type; | ||
|
|
||
| cin >> n; | ||
| map<string, int> wear; | ||
|
|
||
| //입력 | ||
| for(int i=0; i<n; i++){ | ||
| cin >> name >> type; | ||
| wear[type]++; | ||
|
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(auto iter = wear.begin(); iter != wear.end(); iter++){ | ||
| ans *= (*iter).second+1; | ||
| } | ||
|
|
||
| //아무것도 입지 않는 경우 빼고 출력 | ||
| cout << ans-1 << '\n'; | ||
| } | ||
| } | ||
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.
string을 가공하지 않고 너무 잘 풀어주셨어요!!!! 👍 가독성 면에서 조금 코멘트를 드리자면, res 벡터를 push_back 으로 일의 자리 수부터 저장한 후, 끝에서부터 출력하는 형태로 하면 출력을 하나로 합칠 수 있어요!!