Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions 9월 7일 - 정렬/1026.cpp
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;
vector<int> a(n), b(n);
vector<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.begin(), a.end());

sort(b.begin(), b.end(), greater<>());

int sum = 0;
for(int i=0; i<n; i++){
sum += a[i]*b[i];
}

cout << sum;
}

40 changes: 40 additions & 0 deletions 9월 7일 - 정렬/10994.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#include <iostream>
#include <vector>

using namespace std;

void solve(int x, int y, int start_len, int length, vector<vector<char>> &star){

if(x == start_len / 2 && y == start_len / 2){
star[x][y] = '*';
return;
}

for(int i=x; i<x+length; i++){
star[i][y] = '*';
star[i][y+length-1] = '*';
star[x][i] = '*';
star[x+length-1][i] = '*';
}

solve(x+2, y+2, start_len, length-4, star);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테두리 별이 4씩 줄어든다는 규칙을 아주 잘 파악하셨군요 ! 👍 재귀로 너무 잘 구현해주셨어요

}

int main(){
int n;
cin >> n;
int length = 4*n-3;

vector<vector<char>> star(length,vector<char>(length, ' '));

solve(0, 0, length, length, star);

for(int i=0; i<length; i++){
for(int j=0; j<length; j++)
cout << star[i][j];
cout << '\n';
}
}


23 changes: 23 additions & 0 deletions 9월 7일 - 정렬/11399.cpp
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];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O(n^2) 풀이를 생각하기가 쉬운데, O(n) 풀이를 해주시다니 최고에요! 👍👍👍

}

cout << sum;
}

27 changes: 27 additions & 0 deletions 9월 7일 - 정렬/11651.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool comp(const pair<int, int> &i1, const pair<int, int> &i2){
if(i1.second != i2.second)
return i1.second < i2.second;
return i1.first < i2.first;
}

int main(){
int n;
cin >> n;
vector<pair<int, int>> xy(n);

for(int i=0; i<n; i++){
cin >> xy[i].first >> xy[i].second;
}

sort(xy.begin(), xy.end(), comp);

for(int i=0; i<n; i++){
cout << xy[i].first << " " << xy[i].second << '\n';
}
}
36 changes: 36 additions & 0 deletions 9월 7일 - 정렬/1316.cpp
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) {
Copy link

Choose a reason for hiding this comment

The 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;
}
33 changes: 33 additions & 0 deletions 9월 7일 - 정렬/13458.cpp
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++;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완벽해요! 👍

}
}
}

cout << count;
}
42 changes: 42 additions & 0 deletions 9월 7일 - 정렬/1431.cpp
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))
Copy link

Choose a reason for hiding this comment

The 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';
}
}
41 changes: 41 additions & 0 deletions 9월 7일 - 정렬/1946.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#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;

//입력, 정렬
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());

cout << solution(v, n) << '\n';
}

}