-
Notifications
You must be signed in to change notification settings - Fork 0
[정렬] 9월 7일 #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?
The head ref may contain hidden characters: "\uC815\uB82C"
[정렬] 9월 7일 #1
Changes from 1 commit
fdce905
7f14a28
260bb6f
f825072
4693e9b
6a6bff9
b8af062
48b8c8c
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,29 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <algorithm> | ||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
| int a[n], b[n]; | ||
| bool check[n]; | ||
| for(int i=0; i<n; i++){ | ||
| cin >> a[i]; | ||
| } | ||
| for(int i=0; i<n; i++){ | ||
| cin >> b[i]; | ||
| } | ||
|
|
||
| sort(a, a+n); | ||
|
|
||
| sort(b, b+n); | ||
|
|
||
| int sum = 0; | ||
| for(int i=0; i<n; i++){ | ||
| sum += a[i]*b[n-i-1]; | ||
|
||
| } | ||
|
|
||
| cout << sum; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| void solve(int x, int y, int start_len, int length, char star[][400]){ | ||
|
|
||
| if(x == start_len / 2 && y == start_len / 2){ | ||
| star[x][y] = '*'; | ||
| return; | ||
| } | ||
|
|
||
| for(int i=x; i<x+length; i++){ | ||
| if(i==x || i==x+length-1){ | ||
| for(int j=y; j<y+length; j++){ | ||
| star[i][j] = '*'; | ||
|
||
| } | ||
| } | ||
| else{ | ||
| star[i][y] = '*'; | ||
| star[i][y+length-1] = '*'; | ||
| } | ||
| } | ||
|
|
||
| solve(x+2, y+2, start_len, length-4, star); | ||
|
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. 테두리 별이 4씩 줄어든다는 규칙을 아주 잘 파악하셨군요 ! 👍 재귀로 너무 잘 구현해주셨어요 |
||
| } | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
| int length = 1+(n-1)*4; | ||
|
||
|
|
||
| char star[400][400]; | ||
|
|
||
| solve(0, 0, length, length, star); | ||
|
|
||
| for(int i=0; i<length; i++){ | ||
| for(int j=0; j<length; j++){ | ||
| if(star[i][j] == '*'){ | ||
| cout << star[i][j]; | ||
| } | ||
| else | ||
| cout << " "; | ||
|
||
| } | ||
| cout << '\n'; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <algorithm> | ||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
| int arr[n]; | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| cin >> arr[i]; | ||
| } | ||
|
|
||
| sort(arr, arr+n); | ||
| int sum = 0; | ||
| for(int i=0; i<n; i++){ | ||
| sum += (n-i)*arr[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. O(n^2) 풀이를 생각하기가 쉬운데, O(n) 풀이를 해주시다니 최고에요! 👍👍👍 |
||
| } | ||
|
|
||
| cout << sum; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
| #include <algorithm> | ||
| using namespace std; | ||
|
|
||
| struct xy{ | ||
| int x,y; | ||
| }; | ||
|
||
|
|
||
| bool comp(const xy &i1, const xy &i2){ | ||
| if(i1.y != i2.y) | ||
| return i1.y < i2.y; | ||
| return i1.x < i2.x; | ||
|
||
| } | ||
|
|
||
| int main(){ | ||
| int n; | ||
| vector<xy> xy; | ||
| cin >> n; | ||
|
|
||
| xy.assign(n, {}); | ||
| for(int i=0; i<n; i++){ | ||
| cin >> xy[i].x >> xy[i].y; | ||
| } | ||
|
|
||
| sort(xy.begin(), xy.end(), comp); | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| cout << xy[i].x << " " << xy[i].y << '\n'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include <iostream> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| int n; | ||
| cin >> n; | ||
| bool check = true; | ||
| int count = 0; | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| check = true; | ||
| string s; | ||
| cin >> s; | ||
| int len = s.length(); | ||
|
|
||
| for(int j=0; j<len; j++){ | ||
| char ch = s.at(j); | ||
|
||
|
|
||
| while(j<len-1 && s.at(j+1) == ch){ | ||
| j++; | ||
| } | ||
|
|
||
| for(int k=j+1; k<len; k++){ | ||
| if(s.at(k) == ch){ | ||
| check = false; | ||
|
||
| } | ||
| } | ||
| } | ||
| if(check) | ||
|
||
| count++; | ||
| } | ||
|
|
||
| cout << count; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
| int arr[n]; | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| cin >> arr[i]; | ||
| } | ||
|
|
||
| int b, c; | ||
| cin >> b >> c; | ||
|
|
||
| long long count = 0; | ||
| for(int i=0; i<n; i++){ | ||
|
|
||
| arr[i] -= b; | ||
| count++; | ||
|
|
||
| if(arr[i] > 0){ | ||
| count += arr[i]/c; | ||
| if(arr[i]%c > 0){ | ||
| count++; | ||
|
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. 완벽해요! 👍 |
||
| } | ||
| } | ||
| } | ||
|
|
||
| cout << count; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <algorithm> | ||
|
|
||
| using namespace std; | ||
|
|
||
| struct serial{ | ||
| string num; | ||
| int length, sum; | ||
| }; | ||
|
|
||
| bool cmp(const serial &i1, const serial &i2){ | ||
| if(i1.num.length() != i2.num.length()) | ||
|
||
| return i1.length < i2.length; | ||
| if(i1.sum != i2.sum) | ||
| return i1.sum < i2.sum; | ||
| return i1.num < i2.num; | ||
| } | ||
|
|
||
| int main(){ | ||
| int n; | ||
| vector<serial> srl; | ||
| cin >> n; | ||
| srl.assign(n, {}); | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| cin >> srl[i].num; | ||
| srl[i].length = srl[i].num.length(); | ||
| } | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| for (int j = 0; j < srl[i].length; j++) { | ||
| if (srl[i].num.at(j) >= 48 && srl[i].num.at(j) <= 57) | ||
|
||
| srl[i].sum += srl[i].num.at(j)-'0'; | ||
| } | ||
| } | ||
|
|
||
| sort(srl.begin(), srl.end(), cmp); | ||
|
|
||
| for(int i=0; i<n; i++) { | ||
| cout << srl[i].num << '\n'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
| #include <algorithm> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int solution(int n) { | ||
| vector<pair<int, int>> v; | ||
| v.assign(n, {}); | ||
|
||
|
|
||
| for(int i=0; i<n; i++){ | ||
| cin >> v[i].first >> v[i].second; | ||
| } | ||
|
||
|
|
||
| sort(v.begin(), v.end()); | ||
|
|
||
| int count = n; | ||
| int temp = v[0].second; | ||
| for(int i=1; i<n; i++){ | ||
| if(v[i].second > temp) | ||
| count--; | ||
|
||
| else | ||
| temp = v[i].second; | ||
| } | ||
|
|
||
| return count; | ||
|
|
||
| } | ||
|
|
||
| int main(){ | ||
| int t; | ||
| cin >> t; | ||
|
|
||
| int answer[t]; | ||
|
|
||
| for(int i=0; i<t; i++){ | ||
| int n; | ||
| cin >> n; | ||
| answer[i] = solution(n); | ||
| } | ||
|
|
||
| for(int i=0; i<t; i++){ | ||
| cout << answer[i] << '\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.
배열도 좋지만, c++에 익숙해지기 위해 vector 사용도 추천드립니다!