-
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 4 commits
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,36 @@ | ||
| #include <iostream> | ||
| using namespace std; | ||
|
|
||
| bool checker(string s){ | ||
| bool check [26] = {}; | ||
| int len = s.length(); | ||
|
|
||
| for(int j=0; j<len; j++){ | ||
| char ch = s[j]; | ||
| if (check[ch - 'a']) | ||
| return false; | ||
| check[ch-'a'] = true; | ||
| while(s[j+1] == ch) { | ||
|
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) 풀이로 너무 잘 해주셨어요!!! 👍 지금처럼 while문으로 한 번에 같은문자를 처리하는 것도 좋지만, 겉에 for문에서 인덱스 증가가 이루어지고 있으므로 이 점을 활용하여 여기서 if문 + continue 로 처리를 하는 것도 좋아요~! |
||
| j++; | ||
| } | ||
| if (j == len - 1) | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| int main() { | ||
| int n; | ||
| cin >> n; | ||
| bool check = true; | ||
| int count = 0; | ||
|
|
||
| for(int i=0; i<n; i++) { | ||
| string s; | ||
| cin >> s; | ||
| if(checker(s)) | ||
| 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,42 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <algorithm> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int sum(string s){ | ||
| int sum = 0; | ||
|
|
||
| for (int j = 0; j < s.length(); j++) { | ||
| if (s[j] >= '0' && s[j] <= '9') | ||
| sum += s[j]-'0'; | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| bool cmp(const string &i1, const string &i2){ | ||
| if(i1.length() != i2.length()) | ||
| return i1.length() < i2.length(); | ||
| if(sum(i1) != sum(i2)) | ||
|
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 sum(i1) < sum(i2); | ||
| return i1 < i2; | ||
| } | ||
|
|
||
| int main() { | ||
| int n; | ||
| cin >> n; | ||
| string num[n]; | ||
|
|
||
| //입력 | ||
| for (int i = 0; i < n; i++) { | ||
| cin >> num[i]; | ||
| } | ||
|
|
||
| //정렬 | ||
| sort(num, num+n, cmp); | ||
|
|
||
| //출력 | ||
| for (int i = 0; i < n; i++) { | ||
| cout << num[i] << '\n'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
| #include <algorithm> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int solution(vector<pair<int, int>> v, int n) { | ||
|
|
||
| int count = 1; | ||
| int temp = v[0].second; | ||
| for(int i=1; i<n; i++){ | ||
| if(v[i].second < temp) { | ||
| count++; | ||
| temp = v[i].second; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
|
|
||
| } | ||
|
|
||
| int main(){ | ||
| int t; | ||
| cin >> t; | ||
|
|
||
| vector<int> ans(t); | ||
|
|
||
| //입력, 정렬 | ||
| for(int i=0; i<t; i++){ | ||
| int n; | ||
| cin >> n; | ||
| vector<pair<int, int>> v(n); | ||
| for(int j=0; j<n; j++){ | ||
| cin >> v[j].first >> v[j].second; | ||
| } | ||
|
|
||
| sort(v.begin(), v.end()); | ||
|
|
||
| ans[i] = solution(v, n); | ||
|
||
| } | ||
|
|
||
| //출력 | ||
| for(int i=0; i<t; i++){ | ||
| cout << ans[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 사용도 추천드립니다!