Skip to content
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

EUNA-319 #53

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
01d7835
EUNA-319 boj11279
sung-silver Sep 12, 2021
5c5d424
Merge branch 'StepByStep-Algorithm:main' into main
sung-silver Sep 15, 2021
d7853b8
EUNA-319 boj2752
sung-silver Sep 16, 2021
61b3424
EUNA-319 boj2959
sung-silver Sep 16, 2021
4464aca
EUNA-319 boj2959 알고리즘 정리
sung-silver Sep 16, 2021
1ca4192
EUNA-319 boj2693
sung-silver Sep 17, 2021
a5b4434
EUNA-319 boj10867
sung-silver Sep 17, 2021
1d47e74
EUNA-319 boj2693
sung-silver Sep 17, 2021
fa27f13
EUNA-319 boj10814
sung-silver Sep 17, 2021
1063ef0
Merge branch 'StepByStep-Algorithm:main' into main
sung-silver Sep 21, 2021
de9ab82
Merge branch 'StepByStep-Algorithm:main' into main
sung-silver Sep 25, 2021
a312307
EUNA-319 3week readme
sung-silver Sep 25, 2021
12732a3
Delete WEEK3-B/EUNA-319 directory
sung-silver Sep 25, 2021
b36e304
EUNA-319
sung-silver Sep 25, 2021
969f021
EUNA-319 boj11723
sung-silver Sep 25, 2021
02b9c8b
Merge branch 'StepByStep-Algorithm:main' into main
sung-silver Sep 25, 2021
7c3ca08
EUNA-319 3주차 정리
sung-silver Sep 28, 2021
add1dfd
EUNA-319 boj1790
sung-silver Sep 28, 2021
fdf2df8
EUNA-319 boj1790
sung-silver Sep 28, 2021
e46d7b9
EUNA-319 boj13706
sung-silver Oct 2, 2021
6bce83d
EUNA-319 boj10829
sung-silver Oct 2, 2021
869aef8
EUNA-319 boj10829
sung-silver Oct 2, 2021
5f89c81
EUNA319 - 4week readme
sung-silver Oct 2, 2021
833ba07
EUNA-319 boj1769
sung-silver Oct 2, 2021
d145075
EUNA-319 boj2630
sung-silver Oct 30, 2021
f3e5678
EUNA-319
sung-silver Nov 13, 2021
efac988
boj1260
sung-silver Nov 13, 2021
8469a4f
Update README.md
sung-silver Nov 14, 2021
7184b66
Merge branch 'StepByStep-Algorithm:main' into main
sung-silver Jan 12, 2022
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
30 changes: 30 additions & 0 deletions WEEK1-B/EUNA-319/boj11279.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>
#include<queue>
using namespace std;

int n; // 입력받을 정수의 개수
priority_queue<int> pq;
int main() {

cin.sync_with_stdio(0);
cin.tie(0);

cin >> n;
for (int i=0;i<n;i++) { // 연산의 개수만큼 반복
int x; // 연산에 대한 정보를 받아줄 변수
cin >> x;
if (x == 0) { //x가 0이라면 (0이 입력된 시점에서의 가장 큰 값을 출력하기 때문)
if (pq.empty()) cout << "0\n";
// queue가 비어있을 경우 0 출력
else {
cout << pq.top() << "\n";
pq.pop();
// 가장 위에 들어가있는 값을 출력
// pop()을 해주면 queue의 선입선출 특징으로 맨위의 값이 나오게 됨
}
} else { // x가 0이 아니라면
pq.push(x); // 입력한 숫자를 priority_queue에 삽입
}
}
return 0;
}
37 changes: 37 additions & 0 deletions WEEK2-B/EUNA-319/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## 백준 2959 알고리즘 정리 ##
<br>

### 사용한 알고리즘 : Buble Sotring ###

- 서로 인접한 두 원소를 검사하여 정렬하는 알고리즘<br>
&nbsp;&nbsp;-> 인접한 2개의 레코드를 비교하여 크기가 순서대로 되어 있지 않으면 서로 교환함
- 오름차순을 기준으로 정렬
- 선택 정렬과 기본 개념이 유사함
<br><br>

### 버블 정렬의 구현 ###
- 순회할 원소의 개수가 하나씩 줄어든다는 점
```c++
// Bubble Sort
for (i = 0; i < N; i++) {
for (j = 0; j < N-(i+1); j++) {
if (data[j] > data[j+1]) {
// 자리교환
temp = data[j+1];
data[j+1] = data[j];
data[j] = temp;
}
}
}

```

### 문제 풀 때 생각한 flow ###
- 단순하게 정렬해서 출력하면 됨 이때 띄어쓰기 횟수에 주의함
<br><br>

### 새롭게 공부한 내용 ###
- 내가 구현한 방법이 버블 정렬과 유사하다는 점을 알 수 있었음
- 이미 c++에는 정렬 알고리즘이 있음 -> C++ STL sort()
- sort(): 기본적으로 오름차순 정렬을 수행<br>
&nbsp;&nbsp;-> 배열의 시작점 주소와 마지막 주소+1을 인자로 주면 됨
33 changes: 33 additions & 0 deletions WEEK2-B/EUNA-319/boj10814.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct List{
int age;
string name;
};

bool compare(const List &i, const List &j){
return i.age<j.age;
}

int main() {
int tc;
cin>>tc;
vector <List> person;
List list;

for(int i=0; i<tc;i++){
cin>>list.age>>list.name;
person.push_back(list);
}
stable_sort(person.begin(),person.end(),compare);

for(int i=0;i<tc;i++){
cout<<person[i].age<<" "<<person[i].name<<"\n";
}

}


17 changes: 17 additions & 0 deletions WEEK2-B/EUNA-319/boj10867.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int tc;
cin>>tc;
int *a = new int[tc];
for(int i=0;i<tc;i++){
cin>>a[i];
}
sort(a,a+tc);
cout<<a[0];
for(int i=1;i<tc;i++){
if(a[i]!=a[i-1]) cout<<" "<<a[i];
}
}
14 changes: 14 additions & 0 deletions WEEK2-B/EUNA-319/boj2693.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int a[10];
int tc;
cin>>tc;
for(int i=0;i<tc;i++){
scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
sort(a,a+10);
cout<<a[7]<<"\n";
}
}
33 changes: 33 additions & 0 deletions WEEK2-B/EUNA-319/boj2752.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;

void sorting(int* arr);

int main() {
int v[3];
int i=0, num;
while(i<3){ // 3개의 수 입력받기
cin>>num;
v[i]=num;
i++;
}
sorting(v);
}

void sorting(int* arr){ // 포인터로 함수 인자 전달
int temp; // 수를 바꿀 때 사용
for(int i=0;i<2;i++){ // 앞에 있는 수가 뒤에 있는 수 보다 작다면 계속해서 뒤로 밀림
for(int j=i+1;j<3;j++){ // i보다 큰 숫자들에 대해 비교 반복
if(arr[i]>arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0;i<3;i++) {
cout<<arr[i];
if(i!=2) cout<<" ";
}
cout<<"\n";
}
29 changes: 29 additions & 0 deletions WEEK2-B/EUNA-319/boj2959.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;

int sorting(int* arr);

int main() {
int v[4];
int i=0, num;
while(i<4){ // 4개의 수 입력받기
cin>>num;
v[i]=num;
i++;
}
cout<<sorting(v);
}

int sorting(int* arr){ // 포인터로 함수 인자 전달
int temp; // 수를 바꿀 때 사용
for(int i=0;i<3;i++){ // 앞에 있는 수가 뒤에 있는 수 보다 작다면 계속해서 뒤로 밀림
for(int j=i+1;j<4;j++){ // i보다 큰 숫자들에 대해 비교 반복
if(arr[i]>arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
return arr[0]*arr[2]; // 정렬된 4개의 수 중 인덱스 0번쨰와 2번째의 수를 곱한 것이 거북이가 움직인 거리로 만들 수 있는 직사각형의 크기
}
21 changes: 21 additions & 0 deletions WEEK3-B/EUNA-319/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## 백준 5086 알고리즘 정리 ##
<br><br>

### 사용한 알고리즘 : 산술 ###

- 배수와 약수의 관계: a와 b
--> a가 b의 약수일 때 b는 a의 배수
--> a가 b의 배수일 때 b는 a의 약수
<br><br><br>

### 구현 ###
- 배수와 약수의 관계를 파악하여 품
```c++
string trans(unsigned int a, unsigned int b){
if(b%a==0) return "factor";
else if(a%b==0) return "multiple";
else return "neither";
}

```

34 changes: 34 additions & 0 deletions WEEK3-B/EUNA-319/boj11723.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <cstring>
using namespace std;
bool checkNum[21];
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
int n;
cin>>n;
for(int i=0;i<n;i++) {
int x;
string str;
cin>>str;
if (str=="add") {
cin>>x;
checkNum[x]=true;
} else if (str=="remove") {
cin>>x;
checkNum[x]=false;
} else if (str=="check") {
cin>>x;
checkNum[x] ? (puts("1")) : (puts("0"));
} else if (str=="toggle") {
cin>>x;
checkNum[x] ? (checkNum[x]=false) : (checkNum[x]=true);
} else if (str=="all") {
memset(checkNum, true, sizeof(checkNum));
} else {
memset(checkNum, false, sizeof(checkNum));
}
}
return 0;
}

43 changes: 43 additions & 0 deletions WEEK3-B/EUNA-319/boj15953.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
using namespace std;

unsigned int cal(unsigned int a, unsigned b);


int main() {
unsigned int n, a=0, b=0;
cin.sync_with_stdio(0);
cin.tie(0);

cin>>n;
cin.ignore();
for(int i=0;i<n;i++){
cin>>a>>b;
cin.ignore();
cout<<cal(a,b)<<endl;
}

}

unsigned int cal(unsigned int a, unsigned b){
if(a>21||a==0) a=0; //본선 진출 X와 순위권 X를 고려
else{
if(a==1) a=5000000;
else if(3>=a) a=3000000;
else if(6>=a) a=2000000;
else if(10>=a) a= 500000;
else if(15>=a) a=300000;
else a=100000;
}

if(b>31||b==0) b=0; // 본선 진출 X와 순위권 X를 고려
else{
if(b==1) b=5120000;
else if(3>=b) b=2560000;
else if(7>=b) b=1280000;
else if(15>=b) b= 640000;
else b=320000;
}

return a+b;
}
33 changes: 33 additions & 0 deletions WEEK3-B/EUNA-319/boj1790.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;

int length(unsigned int a);

int main() {
int n,k,len=0,i,j;
cin>>n>>k;

for(i=1;i<=n;i++) {
len += length(i);
if (len >= k) break;
}
if(len == k){
cout<<i%10;
}
else if(k>len) cout<< -1;
else{
for(j=0; j<len-k; j++){
i /= 10;
}
cout<<i%10;
}
}

int length(unsigned int a){
int sum=0;
while(a>0){
sum++;
a/=10;
}
return sum;
}
29 changes: 29 additions & 0 deletions WEEK3-B/EUNA-319/boj2941.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;

int main() {
string str;
int count = 0;
cin>>str;
for (int i = 0; i<str.length(); i++) {
if (str[i] == 'c') {
if (str[i + 1] == '=') i++;
else if (str[i + 1] == '-') i++;
}
if (str[i] == 'd') {
if (str[i + 1] == 'z'&&str[i + 2] == '=') i += 2;
else if (str[i + 1] == '-') i++;
}
if (str[i + 1] == 'j') {
if (str[i] == 'l') i++;
else if (str[i] == 'n') i++;
}
if (str[i + 1] == '=') {
if (str[i] == 's') i++;
else if (str[i] == 'z') i++;
}
count++;
}
cout<<count;
return 0;
}
24 changes: 24 additions & 0 deletions WEEK3-B/EUNA-319/boj5086.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <string>
using namespace std;

string trans(unsigned int a, unsigned int b);

int main() {
unsigned int a, b;
cin.sync_with_stdio(0);
cin.tie(0);

do {
cin >> a >> b;
if(a==0&&b==0) return 0;
cout << trans(a, b)<<endl;
}while(true);
return 0;
}

string trans(unsigned int a, unsigned int b){
if(b%a==0) return "factor";
else if(a%b==0) return "multiple";
else return "neither";
}
Loading