-
Notifications
You must be signed in to change notification settings - Fork 0
[정렬, 맵, 셋] 8월 20일 #1
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?
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,52 @@ | ||
| #include <iostream> | ||
| #include <algorithm> | ||
| #include <string> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int n; | ||
| string a[1000]; | ||
|
|
||
| int integer_sum(string a){ | ||
| int length = a.length(); | ||
| int sum =0; | ||
| for(int i = 0; i <length; i++){ | ||
| if (a[i]-'0' <= 9 && a[i]-'0'>=0){ | ||
|
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 |
||
| sum += a[i] - '0'; | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| bool compare (string a, string b){ | ||
|
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
|
||
| if(a.length()<b.length()){ | ||
| return 1; | ||
| } | ||
| else if (a.length()>b.length()){ | ||
| return 0; | ||
| } | ||
| else { | ||
| int sum_a = integer_sum(a); | ||
| int sum_b = integer_sum(b); | ||
|
|
||
| if (sum_a < sum_b){ | ||
| return 1; | ||
| } | ||
| else if (sum_a > sum_b) { | ||
| return 0; | ||
| } | ||
| else { | ||
| return a < b; | ||
| } | ||
| } | ||
|
Comment on lines
+22
to
+41
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 |
||
| } | ||
| int main(){ | ||
| cin >> n; | ||
| for (int i = 0; i < n; i++){ | ||
| cin >> a[i]; | ||
| } | ||
| sort (a, a+n, compare); | ||
| for (int i = 0; i < n; i++){ | ||
| cout << a[i] << ' ' <<endl; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <set> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int n, m, cnt = 0; | ||
| set <string> s; | ||
|
Comment on lines
+7
to
+8
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 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 main() | ||
| { | ||
| ios_base::sync_with_stdio(0); | ||
| cin.tie(0); | ||
|
|
||
| cin >> n >> m; | ||
| for (int i = 0; i < n; i++){ | ||
| string tmp; | ||
| cin >> tmp; | ||
| s.insert(tmp); | ||
| } | ||
| for (int i = 0; i <m; i++){ | ||
| string tmp; | ||
| cin >> tmp; | ||
| if (s.find(tmp) != s.end()) cnt++; | ||
| } | ||
|
Comment on lines
+21
to
+25
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. P3 |
||
| cout <<cnt; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <iostream> | ||
| #include <cmath> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int w, basic, t, day; | ||
| int d_input, d_output; | ||
|
|
||
| cin >> w >> basic >> t; | ||
| cin >> day >> d_input >> d_output; | ||
|
|
||
| int w1 = w; | ||
| int w2 = w; | ||
|
|
||
| int basic2 = basic; | ||
|
|
||
| for(int i=0; i<day; i++){ | ||
| w1 += d_input - (basic + d_output); | ||
| w2 += d_input - (basic2 + d_output); | ||
|
|
||
| if (abs(d_input - (basic2 + d_output))>t) | ||
| basic2 += floor((d_input - (basic2+d_output))/2.0); | ||
| } | ||
| if (21 <= 0) | ||
| cout << "Danger Diet\n"; | ||
| else | ||
| cout << w1 << " " << basic << "\n"; | ||
|
|
||
| if (w2 <= 0 || basic2 <= 0) | ||
| cout << "Danger Diet\n"; | ||
| else{ | ||
| cout << w2 << " " << basic2 << " "; | ||
| if (basic - basic2 > 0) | ||
| cout << "YOYO"; | ||
| else | ||
| cout << "NO"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| string str; | ||
| cin >> str; | ||
|
|
||
| cout << "알튜비튜 7기 화이팅!" | ||
| cout << "중도하차 안돼요!" | ||
| } |
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.
P1
string이 아닌 vector를 사용해서 main 함수에 n개만큼 초기화해준다면 메모리 측면에서도 효율적이고 훨씬 더 코드가 간결해져요 !