diff --git a/WEEK1-B/EUNA-319/boj11279.cpp b/WEEK1-B/EUNA-319/boj11279.cpp new file mode 100644 index 00000000..03ff9f9f --- /dev/null +++ b/WEEK1-B/EUNA-319/boj11279.cpp @@ -0,0 +1,30 @@ +#include +#include +using namespace std; + +int n; // 입력받을 정수의 개수 +priority_queue pq; +int main() { + + cin.sync_with_stdio(0); + cin.tie(0); + + cin >> n; + for (int i=0;i> 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; +} \ No newline at end of file diff --git a/WEEK2-B/EUNA-319/README.md b/WEEK2-B/EUNA-319/README.md new file mode 100644 index 00000000..eb5d2d2b --- /dev/null +++ b/WEEK2-B/EUNA-319/README.md @@ -0,0 +1,37 @@ +## 백준 2959 알고리즘 정리 ## +
+ +### 사용한 알고리즘 : Buble Sotring ### + +- 서로 인접한 두 원소를 검사하여 정렬하는 알고리즘
+  -> 인접한 2개의 레코드를 비교하여 크기가 순서대로 되어 있지 않으면 서로 교환함 +- 오름차순을 기준으로 정렬 +- 선택 정렬과 기본 개념이 유사함 +

+ +### 버블 정렬의 구현 ### +- 순회할 원소의 개수가 하나씩 줄어든다는 점 + ```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 ### +- 단순하게 정렬해서 출력하면 됨 이때 띄어쓰기 횟수에 주의함 +

+ +### 새롭게 공부한 내용 ### +- 내가 구현한 방법이 버블 정렬과 유사하다는 점을 알 수 있었음 +- 이미 c++에는 정렬 알고리즘이 있음 -> C++ STL sort() +- sort(): 기본적으로 오름차순 정렬을 수행
+   -> 배열의 시작점 주소와 마지막 주소+1을 인자로 주면 됨 \ No newline at end of file diff --git a/WEEK2-B/EUNA-319/boj10814.cpp b/WEEK2-B/EUNA-319/boj10814.cpp new file mode 100644 index 00000000..09aa7db4 --- /dev/null +++ b/WEEK2-B/EUNA-319/boj10814.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +using namespace std; + +struct List{ + int age; + string name; +}; + +bool compare(const List &i, const List &j){ + return i.age>tc; + vector person; + List list; + + for(int i=0; i>list.age>>list.name; + person.push_back(list); + } + stable_sort(person.begin(),person.end(),compare); + + for(int i=0;i +#include +using namespace std; + +int main() { + int tc; + cin>>tc; + int *a = new int[tc]; + for(int i=0;i>a[i]; + } + sort(a,a+tc); + cout< +#include +using namespace std; + +int main() { + int a[10]; + int tc; + cin>>tc; + for(int i=0;i +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< +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<arr[j]){ + temp=arr[i]; + arr[i]=arr[j]; + arr[j]=temp; + } + } + } + return arr[0]*arr[2]; // 정렬된 4개의 수 중 인덱스 0번쨰와 2번째의 수를 곱한 것이 거북이가 움직인 거리로 만들 수 있는 직사각형의 크기 +} \ No newline at end of file diff --git a/WEEK3-B/EUNA-319/README.md b/WEEK3-B/EUNA-319/README.md new file mode 100644 index 00000000..10a20f99 --- /dev/null +++ b/WEEK3-B/EUNA-319/README.md @@ -0,0 +1,21 @@ +## 백준 5086 알고리즘 정리 ## +

+ +### 사용한 알고리즘 : 산술 ### + +- 배수와 약수의 관계: a와 b + --> a가 b의 약수일 때 b는 a의 배수 + --> a가 b의 배수일 때 b는 a의 약수 +


+ +### 구현 ### +- 배수와 약수의 관계를 파악하여 품 + ```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"; +} + + ``` + diff --git a/WEEK3-B/EUNA-319/boj11723.cpp b/WEEK3-B/EUNA-319/boj11723.cpp new file mode 100644 index 00000000..6a82c60d --- /dev/null +++ b/WEEK3-B/EUNA-319/boj11723.cpp @@ -0,0 +1,34 @@ +#include +#include +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>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; +} + diff --git a/WEEK3-B/EUNA-319/boj15953.cpp b/WEEK3-B/EUNA-319/boj15953.cpp new file mode 100644 index 00000000..4b9fd687 --- /dev/null +++ b/WEEK3-B/EUNA-319/boj15953.cpp @@ -0,0 +1,43 @@ +#include +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>a>>b; + cin.ignore(); + cout<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; +} diff --git a/WEEK3-B/EUNA-319/boj1790.cpp b/WEEK3-B/EUNA-319/boj1790.cpp new file mode 100644 index 00000000..ae2dc00f --- /dev/null +++ b/WEEK3-B/EUNA-319/boj1790.cpp @@ -0,0 +1,33 @@ +#include +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<len) cout<< -1; + else{ + for(j=0; j0){ + sum++; + a/=10; + } + return sum; +} diff --git a/WEEK3-B/EUNA-319/boj2941.cpp b/WEEK3-B/EUNA-319/boj2941.cpp new file mode 100644 index 00000000..648113e0 --- /dev/null +++ b/WEEK3-B/EUNA-319/boj2941.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main() { + string str; + int count = 0; + cin>>str; + for (int i = 0; i +#include +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)<
+ +### 재귀 ### +- 자기 자신을 호출하는 함수 +- 자신의 복사본을 호출하여 더 작은 문제를 풀게함으로써 문제를 해결 +- 기본 경우: 함수가 재귀 호출을 하지 않는 것 +- 재귀 경우: 자기 자신을 호출해서 하위 작업을 수행하는 것 +

+ +### 이분 탐색 ### +- 탐색 기법 중 하나로 원하는 탐색 범위를 두 부분으로 분할해서 찾는 방식 +- 원래의 전부를 탐색하는 속도에 비해 빠름 +- left, right, mid 값으로 탐색하는 것 +- mid의 값은 (left+right)/2으로 잡아주고 검색하고자 하는 값과 mid를 비교 +- 조건: 정렬이 되어있어야 함 + ```c++ + #include + int main(void){ + + int findN; + int result = 0; + //처음int는 다음 정점 마지막 int 값어치 + + int A[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 15 }; + + scanf("%d", &findN); + int left = 0, right = 9; + + + while (left <= right){ + + int mid = (left + right) / 2; + if (A[mid] > findN) + right = mid - 1; + else if (A[mid] < findN) + left = mid + 1; + else + { + result = mid; + break; + } + + } + + printf("%d\n", result); + + return 0; + } + ``` + + diff --git a/WEEK4-B/EUNA-319/boj10829.cpp b/WEEK4-B/EUNA-319/boj10829.cpp new file mode 100644 index 00000000..16a83bf3 --- /dev/null +++ b/WEEK4-B/EUNA-319/boj10829.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +void to_bin(long number) { + if (number == 0 || number == 1) { + cout << number; + } + else { + to_bin(number / 2); + cout << number % 2; + } +} + +int main() { + long a; + cin>>a; + to_bin(a); +} diff --git a/WEEK4-B/EUNA-319/boj13706.cpp b/WEEK4-B/EUNA-319/boj13706.cpp new file mode 100644 index 00000000..ba651f09 --- /dev/null +++ b/WEEK4-B/EUNA-319/boj13706.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace std; + +int main() { + int n; + cin>>n; + int low = 1; + int high = n; + int mid; + + while (1) { + mid = (low + high); // 2 + if(pow(mid,2) == n) { + cout< n) + high = mid - 1; + else if(pow(mid,2) +#include +#include +using namespace std; +void cal(char num[]); + +int main() { + cin.sync_with_stdio(0); + cin.tie(0); + char num[1000001]; + cin >> num; + cal(num); +} + +void cal(char num[]) +{ + int count = 0; + int sum; + while(strlen(num)>1) + { + sum = 0; + for (int i = 0; i < strlen(num); i++) + { + sum += num[i] - '0'; + } + sprintf(num,"%d",sum); + count++; + } + cout << count<< endl; + + if (stoi(num) != 3&&stoi(num)!=6&&stoi(num)!=9) + cout << "NO"; + else + cout << "YES"; +} diff --git a/WEEK4-B/EUNA-319/boj2630.cpp b/WEEK4-B/EUNA-319/boj2630.cpp new file mode 100644 index 00000000..f4c01581 --- /dev/null +++ b/WEEK4-B/EUNA-319/boj2630.cpp @@ -0,0 +1,43 @@ +// BOJ 2630번 : 색종이 만들기 +#include +using namespace std; +void dfs(int x, int y, int size); +int arr[128][128]; +int white = 0, blue = 0; + +int main() { + int n; + cin >> n; + for(int i = 0; i < n; i++) + for(int j = 0; j < n; j++) + cin >> arr[i][j]; // 배열 입력받기 + + dfs(0, 0, n); + cout << white << "\n" << blue << "\n"; +} + +void dfs(int x, int y, int n){ + bool w = true, b = true; // w와 b 초깃값 true + for(int i = x; i < x + n; i++){ // x + n까지 반복 + for(int j = y; j < y + n; j++){ // y + n까지 반복 + if(arr[i][j] == 1) // 만약 하얀색이라면 + w = false; // w를 false로 + if(arr[i][j] == 0) // 파란색이라면 + b = false; // b를 false로 + } + } + if(w == true){ // w가 true라면 (하얀색으로 채워진 것) + white++; // white 증가 + return; + } + if(b == true){ // b가 true라면 (파란색으로 채워진 것) + blue++; // blue 증가 + return; + } + + // 재귀호출 + dfs(x, y, n / 2); + dfs(x, y + n / 2, n / 2); + dfs(x + n / 2, y, n / 2); + dfs(x + n / 2, y + n / 2, n / 2); +} \ No newline at end of file diff --git a/WEEK5-B/EUNA-319/README.md b/WEEK5-B/EUNA-319/README.md new file mode 100644 index 00000000..20ac1ec1 --- /dev/null +++ b/WEEK5-B/EUNA-319/README.md @@ -0,0 +1,39 @@ +## 그래프 (탐색, DFS, BFS) ## +

+ +### 탐색 ### +- 탐색: 다수의 레코드 집합에서 특정 키 값과 일치하는 레코드를 찾는 작업 +- 레코드는 객체의 속성에 해당하는 필드들의 집합으로 표현 +- 레코드를 식별하는데 사용되는 필드를 키 필드라고 부르고 키 필드를 통하여 레코드의 탐색이 이루어짐 +- 레코드의 집합을 리스트라고하는데 리스트의 파일 형식으로 디스크에 저장됨 +- 리스트의 레코드가 정렬되어 있는 경우 탐색 효율이 높아짐 +

+ +### DFS ### +- 인접 리스트의 시작 노드에서 출발하여 새로운 노드를 만날 때마다 해당 노드의 연결리스트로 분기하여 탐색하는 방법으로 함수 호출 구조와 유사 +- 특정 노드의 연결 리스트에 존재하는 인접 노드들을 모두 방문하면 해당 노드를 호출한 이전 노드의 연결 리스트로 돌아가서 미방문 노드를 계속 탐색 +- 시작 노드의 연결 리스트가 모두 방문되면 탐색을 종료 + + ```c++ + 정점(v)를 방문한 것으로 표시한다 + for(정점(v)에 인접한 모든 미방문 정점(u)에 대하여) + DFS(u) + } + ``` + - DFS 탐색을 통하여 그래프의 특정 노드를 포함하는 컴포넌트를 탐색할 수 있음 + - DFS 탐색은 그래프의 연결성을 확인하는데 사용됨 + - 연결 그래프가 아닌 경우 모든 노드가 탐색되지 않음 + - DFS 방법으로 방문할 때 사용된 간선만으로 이루어진 서브 그래프를 DSF 신장 트리 (DFS spanning tree)라고 함 + + ### BFS ### +- 큐를 이용하여 그래프를 탐색하는 방법 +- 트리의 레벨 순서 탐색과 유사 + ``` + 시작 정점 (1)을 방문한 것으로 표시하고 출력한 후 큐에 삽입 + 큐에서 이 정점을 다시 꺼내어 이 정점의 인접 리스트를 탐색하여 미방문 정점이 있으면 큐에 삽입 + 인접 리스트의 노드 탐색이 끝나면 큐에서 새로운 노드를 꺼내어 이 과정을 반복 + 큐에 더 이상 노드가 없으면 탐색을 종료 + + ``` + + diff --git a/WEEK5-B/EUNA-319/boj1260.cpp b/WEEK5-B/EUNA-319/boj1260.cpp new file mode 100644 index 00000000..de9bba85 --- /dev/null +++ b/WEEK5-B/EUNA-319/boj1260.cpp @@ -0,0 +1,66 @@ +#include +#include +using namespace std; +#define MAX 1001 + +int N, M, V; //정점개수, 간선개수, 시작정점 +int map[MAX][MAX]; //인접 행렬 그래프 +bool visited[MAX]; //정점 방문 여부 +queue q; + +void reset() { + for (int i = 1; i <= N; i++) { + visited[i] = 0; + } +} + +void DFS(int v) { + visited[v] = true; + cout << v << " "; + + for (int i = 1; i <= N; i++) { + if (map[v][i] == 1 && visited[i] == 0) { //현재 정점과 연결되어있고 방문되지 않았으면 + DFS(i); + } + } +} + +void BFS(int v) { + q.push(v); + visited[v] = true; + cout << v << " "; + + while (!q.empty()) { + v = q.front(); + q.pop(); + + for (int w = 1; w <= N; w++) { + if (map[v][w] == 1 && visited[w] == 0) { //현재 정점과 연결되어있고 방문되지 않았으면 + q.push(w); + visited[w] = true; + cout << w << " "; + } + } + } +} + +int main() { + cin >> N >> M >> V; + + for (int i = 0; i < M; i++) { + int a, b; + cin >> a >> b; + map[a][b] = 1; + map[b][a] = 1; + } + + reset(); + DFS(V); + + cout << '\n'; + + reset(); + BFS(V); + + return 0; +} diff --git a/WEEK5-B/EUNA-319/boj3972.cpp b/WEEK5-B/EUNA-319/boj3972.cpp new file mode 100644 index 00000000..2526888b --- /dev/null +++ b/WEEK5-B/EUNA-319/boj3972.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; + +int main() { + int t, n, m,a,b; + cin>>t; + for(int i=0;i>n>>m; + for(int j=0;j>a>>b; + } + cout<