diff --git a/README.md b/README.md index 9876aca..13cb24a 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ | 1주차 (07.07~07.10) | [단어정렬](https://www.acmicpc.net/problem/1181) | [다트게임](https://school.programmers.co.kr/learn/courses/30/lessons/17682) | [파일명정렬](https://school.programmers.co.kr/learn/courses/30/lessons/17686) | [매칭점수](https://school.programmers.co.kr/learn/courses/30/lessons/42893) | [키패드](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [양궁대회](https://school.programmers.co.kr/learn/courses/30/lessons/92342) | [외벽점검](https://school.programmers.co.kr/learn/courses/30/lessons/60062) | | 2주차 (07.14~07.17) | | | | | | | | | 3주차 (07.21~07.24) | | | | | | | | -| 4주차 (07.28~07.31) | | | | | | | | +| 4주차 (07.28~07.31) | | | | | | | | \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-1 \353\213\250\354\226\264\354\240\225\353\240\254.cpp" "b/Week1/BlueStaxks/1-1 \353\213\250\354\226\264\354\240\225\353\240\254.cpp" new file mode 100644 index 0000000..efa456b --- /dev/null +++ "b/Week1/BlueStaxks/1-1 \353\213\250\354\226\264\354\240\225\353\240\254.cpp" @@ -0,0 +1,32 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include +using namespace std; +bool comp(string a, string b) +{ + if (a.length() == b.length()) //길이가 같으면 사전순으로 정렬 + return a < b; + return a.length() < b.length(); //길이가 다르면 긴 순서대로 정렬 +} +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); // 빠른 입출력을 위한 코드 3줄 + int n, i; + cin >> n; + string t; + vector v; + for (i = 0; i < n; ++i) + { + cin >> t; + v.push_back(t); + } //여기까지 그냥 입력 + sort(v.begin(), v.end(), comp); //정렬함수 + v.erase(unique(v.begin(), v.end()), v.end()); //중복 제거 함수 + for (i = 0; i < v.size(); ++i) + cout << v[i] << '\n'; + return 0; +} \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-2 \353\213\244\355\212\270\352\262\214\354\236\204.cpp" "b/Week1/BlueStaxks/1-2 \353\213\244\355\212\270\352\262\214\354\236\204.cpp" new file mode 100644 index 0000000..22740be --- /dev/null +++ "b/Week1/BlueStaxks/1-2 \353\213\244\355\212\270\352\262\214\354\236\204.cpp" @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; +int solution(string dartResult) +{ + int i = 0, s = (int)dartResult.length(); + dartResult += '('; //문자열 bad_excess 방지용 문자 추가(i+1 이런 식으로 탐색할 때 문제가 없어짐) + int m = 1, d = 1, c = 0; + vector v; + for (i = 0; i < s; ++i) + { + if (dartResult[i] == '#') + { + d *= -1; + v.push_back(c * d * m); + d = m = 1; + } + else if (dartResult[i] == '*') + { + m *= 2; + v.push_back(c * d * m); + d = m = 1; + if (v.size() > 1) + v[v.size() - 2] *= 2; + } + else if ('0' <= dartResult[i] && dartResult[i] <= '9') + { + if (i && dartResult[i - 1] != '*' && dartResult[i - 1] != '#') + v.push_back(c * d * m); + c = dartResult[i] - '0'; + if (c == 1 && dartResult[i + 1] - '0' == 0) + { + c = 10; + i++; + } + } + else if (dartResult[i] == 'D') //S는 아무것도 안해도 됨 + c = pow(c, 2); + else if (dartResult[i] == 'T') + c = pow(c, 3); + //printf("%d ", i); + } + if (dartResult[s - 1] != '#' && dartResult[s - 1] != '*') + v.push_back(c * d * m); + int su = 0; + for (i = 0; i < v.size(); ++i) + su += v[i]; + return su; +}// * 3 T / # 9 D ~ + + +#include +int main() +{ + string s = "1T2D3D#"; + printf("%d", solution(s)); + return 0; +} \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-3 \355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.cpp" "b/Week1/BlueStaxks/1-3 \355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.cpp" new file mode 100644 index 0000000..667d68f --- /dev/null +++ "b/Week1/BlueStaxks/1-3 \355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.cpp" @@ -0,0 +1,54 @@ +#include +#include +using namespace std; +bool comp(string &a, string &b) +{ + //printf("*"); + int i = 0, j = 0, t1 = 0, t2 = 0; + char t; + string s1 = "", s2 = ""; + while (!('0' <= a[i] && a[i] <= '9')) //헤드 파트 + { + t = a[i]; + if ('A' <= t && t <= 'Z') + t += 32; + s1 += t; + i++; + } + while (!('0' <= b[j] && b[j] <= '9')) + { + t = b[j]; + if ('A' <= t && t <= 'Z') + t += 32; + s2 += t; + j++; + } + if (s1 != s2) + return s1 < s2; + while (('0' <= a[i] && a[i] <= '9')) //숫자 파트 + { + t1 *= 10; + t1 += a[i] - '0'; + i++; + } + while (('0' <= b[j] && b[j] <= '9')) + { + t2 *= 10; + t2 += b[j] - '0'; + j++; + } + return t1 <= t2; +} +vector solution(vector files) +{ + string t; + for (int i = 0; i < files.size(); ++i) //버블 정렬 + for (int j = 0; j < files.size() - 1 - i; ++j) + if (!comp(files[j], files[j + 1])) + { + t = files[j]; + files[j] = files[j + 1]; + files[j + 1] = t; + } + return files; +} \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-4 \353\247\244\354\271\255\354\240\220\354\210\230.cpp" "b/Week1/BlueStaxks/1-4 \353\247\244\354\271\255\354\240\220\354\210\230.cpp" new file mode 100644 index 0000000..cfe36ad --- /dev/null +++ "b/Week1/BlueStaxks/1-4 \353\247\244\354\271\255\354\240\220\354\210\230.cpp" @@ -0,0 +1,111 @@ +#include +#include +#include +using namespace std; +unordered_map um; +string exOG(string& a) //page의 오리지널 주소 반환 +{ + int p1, p2; + p1 = a.find("\n", p1 + 33); + return a.substr(p1 + 33, p2 - (p1 + 33)); +} +void down(string& a) //소문자로 바꾸기 +{ + int i; + for (i = 0; i < a.length(); ++i) + if ('A' <= a[i] && a[i] <= 'Z') + a[i] += 32; +} +int solution(string word, vector pages) +{ + int i, j, p, p1, p2, p3, c; + int n[20] = {}; //기본 점수 + int ol[20] = {}; //외부 링크 개수 + double s[20] = {}; //최종 점수 + vector pl; + vector v[20]; + down(word); + for (i = 0; i < pages.size(); ++i) + { + pl.push_back(exOG(pages[i])); //pl의 인덱스가 주소 string을 가지고 있음 + um[pl.back()] = i; //um에 string(주소)를 넣으면 그 인덱스가 나옴 + } + for (i = 0; i < pages.size(); ++i) + { + c = 0; + p1 = pages[i].find("/>\n \n\n"); + string t = pages[i].substr(p1 + 20, pages[i].length() - 16 - (p1 + 20)); //t는 내용 + down(t); + t += '*'; //bad_excess를 막기 위해 문자 추가 //찾는 값이 맨 뒤에 있을 수 없게 됨 + p1 = t.find(word); + if (!p1 && !('a' <= t[p1 + word.length()] && t[p1 + word.length()] <= 'z')) //t의 시작부터 찾는 단어가 나올 수 있기에 따로 분류(아래에서 p1-1을 하는데 p1이 0이면 안됨) + c++; + p1 = t.find("", 10); + ol[i]++; + if (um.count(t.substr(9, p1 - 9))) + if (um[t.substr(9, p1 - 9)] != i) //i는 um[pl[i]]와 동일함 + v[um[t.substr(9, p1 - 9)]].push_back(um[pl[i]]); + } + for (j = 1; j < t.length() - 1; ++j) //t(body)에서 단어와 외부 링크를 동시에 검색 + { + if (j <= t.length() - word.length()) + { + p1 = t.substr(j, word.length()).find(word); //p1은 제로 스케일 + if (!p1) //찾는 단어가 j에 딱 있으면 걸림, 그때 p1은 0 + if (!('a' <= t[j - 1] && t[j - 1] <= 'z') && !('a' <= t[j + word.length()] && t[j + word.length()] <= 'z')) //단어 앞 뒤로 알파벳이 있으면 안됨 + { + c++; + j += word.length() - 1; //찾으면 j 점프 + } + } + if (j <= t.length() - 9) + { + p1 = t.substr(j, 9).find("", j + 10); //p2는 t 스케일 + ol[i]++; + if (um.count(t.substr(j + 9, p2 - j - 9))) //unordered_map의 특성상 없는 key를 검색하면 0으로 나오기 때문에 v[0]이 되는 것을 막기 위해 먼저 key가 있는지 확인 + if (um[t.substr(j + 9, p2 - j - 9)] != i) + v[um[t.substr(j + 9, p2 - j - 9)]].push_back(um[pl[i]]); //v[page에 써있는 외부 링크]에 지금 page의 주소를 추가 //이래야 나중에 검색이 쉬움 + p3 = t.find("", p2 + 2); + j = p3 + 2; //외부 링크 처리가 끝나면 j 점프 + } + } + } + n[i] = c; //기본 점수 + } + double td, ms = -1; //여기부턴 점수 집계 + int ri; + for (i = 0; i < pages.size(); ++i) + { + s[i] = (double)n[i]; //먼저 기본 점수로 맞춰두기 + td = 0; + for (j = 0; j < v[i].size(); ++j) //v[i]에는 i로 가는 j들이 있음 + td += (double)n[v[i][j]] / (double)ol[v[i][j]]; + s[i] += td; + if (s[i] > ms) + { + ms = s[i]; + ri = i; + } + } + return ri; +} + + + +#include +int main() +{ + vector t; + t.push_back("\n\n \n \n \n\nBlind Lorem Blind ipsum dolor Blind test sit amet, consectetur adipiscing elit. \n Link to b \n\n"); + t.push_back("\n\n \n \n \n\nSuspendisse potenti. Vivamus venenatis tellus non turpis bibendum, \n Link to a \nblind sed congue urna varius. Suspendisse feugiat nisl ligula, quis malesuada felis hendrerit ut.\n Link to c \n\n"); + t.push_back("\n\n \n \n \n\nUt condimentum urna at felis sodales rutrum. Sed dapibus cursus diam, non interdum nulla tempor nec. Phasellus rutrum enim at orci consectetu blind\n Link to a \n\n"); + cout << solution("BLIND", t); + return 0; +} \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-5 \355\202\244\355\214\250\353\223\234\353\210\204\353\245\264\352\270\260.cpp" "b/Week1/BlueStaxks/1-5 \355\202\244\355\214\250\353\223\234\353\210\204\353\245\264\352\270\260.cpp" new file mode 100644 index 0000000..4943cab --- /dev/null +++ "b/Week1/BlueStaxks/1-5 \355\202\244\355\214\250\353\223\234\353\210\204\353\245\264\352\270\260.cpp" @@ -0,0 +1,67 @@ +#include +#include +#include +using namespace std; +pair nown(int a) +{ + if (a == 1) return { 1,4 }; + if (a == 2) return { 2,4 }; + if (a == 3) return { 3,4 }; + if (a == 4) return { 1,3 }; + if (a == 5) return { 2,3 }; + if (a == 6) return { 3,3 }; + if (a == 7) return { 1,2 }; + if (a == 8) return { 2,2 }; + if (a == 9) return { 3,2 }; + if (a == 0) return { 2,1 }; +} +int dis(pair a, pair b) //거리 구하기 +{ + return abs(a.first - b.first) + abs(a.second - b.second); +} +string solution(vector numbers, string hand) +{ + string answer = ""; + int i; + pair L = { 1,1 }, R = { 3,1 }, n; + for (i = 0; i < numbers.size(); ++i) + { + n = nown(numbers[i]); + if (numbers[i] == 1 || numbers[i] == 4 || numbers[i] == 7) //예외 + { + answer += 'L'; + L = n; + continue; + } + if (numbers[i] == 3 || numbers[i] == 6 || numbers[i] == 9) //예외 + { + answer += 'R'; + R = n; + continue; + } + if (dis(n, L) > dis(n, R)) //2,5,8,0일 때 더 가까운 거리 구하기 + { + answer += 'R'; + R = n; + } + else if (dis(n, L) < dis(n, R)) + { + answer += 'L'; + L = n; + } + else //거리가 같으면 자기 메인 손으로 누르기 + { + if (hand[0] == 'r') + { + answer += 'R'; + R = n; + } + else + { + answer += 'L'; + L = n; + } + } + } + return answer; +} \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-6 \354\226\221\352\266\201\353\214\200\355\232\214.cpp" "b/Week1/BlueStaxks/1-6 \354\226\221\352\266\201\353\214\200\355\232\214.cpp" new file mode 100644 index 0000000..b095718 --- /dev/null +++ "b/Week1/BlueStaxks/1-6 \354\226\221\352\266\201\353\214\200\355\232\214.cpp" @@ -0,0 +1,61 @@ +#include +#include +using namespace std; +vector solution(int n, vector info) +{ + int m[11]; + int i, j, c, ma = 0, s1, s2; + vector r(11, 0); + for (i = 0; i < 10; ++i) + m[i] = info[i] + 1; //1점만 높아도 뺏어갈 수 있음 + m[10] = 0; //0점은 먹으나 안먹으나 다를 게 없으므로 쓰레기통으로 사용 + for (i = 11; i >= 1; --i) + { + vector t(11, false); + for (j = 0; j < i; ++j) + t[j] = true; + do { + c = s1 = s2 = 0; + for (j = 0; j < 11; ++j) + if (t[j]) + c += m[j]; //c는 총 발사 횟수 + if (c <= n) //n보다 커버리면 안됨(작아도 0점에 버리면 되므로 괜춘) + { + for (j = 0; j < 10; ++j) //0은 생각 안하므로 10번만 + { + if (info[j] < m[j] * t[j]) //t는 0아니면 1이기에 곱한 값 더하면 깔끔하게 딱 됨 + s2 += 10 - j; + if (info[j] >= m[j] * t[j] && info[j]) //억울한 라이언 ㅠㅠ + s1 += 10 - j; + } + if (s2 - s1 > ma) //점수차 최대일 시 + { + ma = s2 - s1; + for (j = 0; j < 10; ++j) + r[j] = t[j] * m[j]; + r[10] = n - c; //남은거 다 담기 + } + } + } while (prev_permutation(t.begin(), t.end())); //앞쪽에 true가 몰리므로 prev를 씀 + } + if (ma <= 0) //이러면 못 이기는거임 + { + vector r0(1,-1); + return r0; + } + return r; +} + + +#include +int main() +{ + vector v(11, 0); + vector s; + v[8] = v[10] = 3; + v[9] = 4; + s = solution(10, v); + for (int i = 0; i < s.size(); ++i) + printf("%d ", s[i]); + return 0; +} \ No newline at end of file diff --git "a/Week1/BlueStaxks/1-7 \354\231\270\353\262\275\354\240\220\352\262\200.cpp" "b/Week1/BlueStaxks/1-7 \354\231\270\353\262\275\354\240\220\352\262\200.cpp" new file mode 100644 index 0000000..6eeb3ab --- /dev/null +++ "b/Week1/BlueStaxks/1-7 \354\231\270\353\262\275\354\240\220\352\262\200.cpp" @@ -0,0 +1,53 @@ +#include +#include +using namespace std; +bool cmp(int a, int b) +{ + return a >= b; +} +int solution(int n, vector weak, vector dist) //시계방향, 시계 반대방향, 뭐 다 의미없음 +{ + int i, j, l, p, c, zp, k; + vector tc; + sort(dist.begin(), dist.end(), cmp); //내림차순 정렬 + for (i = 1; i <= dist.size(); ++i) + { + for (j = 0; j < i; ++j) + tc.push_back(dist[j]); //i는 tc의 개수를 정함 //긴 놈부터 들어감 + do { + for (j = 0; j < weak.size(); ++j) //j는 weak를 shift하는 대용이라 보면 됨 + { + zp = weak[j]; //제로 포인트를 맞춰 주는 것. 첫 데이터를 0으로 맞춰버리는 것임 -> 나머지는 zp를 뺀 값으로 하고 그게 음수일 수도 있으므로 +n하고 %n을 함 + p = k = 0; + for (l = 0; l < tc.size(); ++l) + { + c = 0; + p += tc[l]; //p는 계속 제로 스케일에서 움직임 + while ((weak[(k + j) % weak.size()] - zp + n) % n <= p) //커진 p이하의 weak포인트는 k로 다 쩨껴버림 + { + k++; + c = 1; + if (k == weak.size()) + return l + 1; //사실 이건 tc.size()와 같게 됨. 근데 이게 더 안전한 느낌 + } + if (!c) k++; //while문을 들어가 보지도 못하면 k가 안변하므로 따로 k++ + p = (weak[(k + j) % weak.size()] - zp + n) % n; //k가 2까지 됐다면 p는 k가 3인 부분으로 맞춰야 됨 //제로 스케일을 맞추기 위해 -zp, +n, %n이 붙음 //k+j에서도 마찬가지로 %로 값을 맞춰줌 + } + } + } while (prev_permutation(tc.begin(), tc.end())); //tc의 순열을 만들어냄 //tc가 최대값으로 시작하므로 prev //이래야 4 2 3 만큼 써야될 때를 체크 가능 + tc.clear(); //tc 초기화 + } + return -1; //아예 되는 경우가 없으면 여기로 나올거기 때문에 -1로 마무리 +} + + +#include +int main() +{ + vector a(4); + a[0] = 1; a[1] = 5; a[2] = 6; a[3] = 10; + vector b(4); + b[0] = 1; b[1] = 2; b[2] = 3; b[3] = 4; + cout << solution(12, a, b); + return 0; +} \ No newline at end of file diff --git "a/Week2/BlueStaxks/2-1 \352\260\231\354\235\200\354\210\253\354\236\220\353\212\224\354\213\253\354\226\264.cpp" "b/Week2/BlueStaxks/2-1 \352\260\231\354\235\200\354\210\253\354\236\220\353\212\224\354\213\253\354\226\264.cpp" new file mode 100644 index 0000000..a4c0e1b --- /dev/null +++ "b/Week2/BlueStaxks/2-1 \352\260\231\354\235\200\354\210\253\354\236\220\353\212\224\354\213\253\354\226\264.cpp" @@ -0,0 +1,12 @@ +#include +#include +using namespace std; +vector solution(vector arr) +{ + vector r; + r.push_back(arr[0]); + for (int i = 1; i < arr.size(); ++i) + if (arr[i - 1] != arr[i]) //다를 경우만 넣기 + r.push_back(arr[i]); + return r; +} \ No newline at end of file diff --git "a/Week2/BlueStaxks/2-2 \354\230\254\353\260\224\353\245\270\352\264\204\355\230\270.cpp" "b/Week2/BlueStaxks/2-2 \354\230\254\353\260\224\353\245\270\352\264\204\355\230\270.cpp" new file mode 100644 index 0000000..9b6d1af --- /dev/null +++ "b/Week2/BlueStaxks/2-2 \354\230\254\353\260\224\353\245\270\352\264\204\355\230\270.cpp" @@ -0,0 +1,22 @@ +#include +#include +#include +using namespace std; +bool solution(string s) +{ + vector v; //스택처럼 사용 + for (int i = 0; i < s.length(); ++i) + { + if (s[i] == '(') + v.push_back(true); //벡터랑 스택이랑 비슷함 (나중에 넣은 걸 먼저 pop할 수 있음) + else + { + if (v.empty()) //이미 비어있는데 닫으면 오류 + return 0; + v.pop_back(); //닫는 괄호 나오면 팝 + } + } + if (v.empty()) //다 했을 때 v가 비어있어야 정상 + return 1; + return 0; +} \ No newline at end of file diff --git "a/Week2/BlueStaxks/2-3 \352\270\260\353\212\245\352\260\234\353\260\234.cpp" "b/Week2/BlueStaxks/2-3 \352\270\260\353\212\245\352\260\234\353\260\234.cpp" new file mode 100644 index 0000000..465d5ea --- /dev/null +++ "b/Week2/BlueStaxks/2-3 \352\270\260\353\212\245\352\260\234\353\260\234.cpp" @@ -0,0 +1,28 @@ +#include +#include +using namespace std; +vector solution(vector progresses, vector speeds) +{ + vector answer; + int s = (int)speeds.size(), i, p = 0, c; //speeds 와 progresses의 길이는 반드시 같음 + while (1) + { + c = 0; //배포할 기술 개수 + if (progresses[p] >= 100) + { + while (progresses[p] >= 100) + { + c++; + p++; //순서대로 배포해야 하기 때문에 증가만 하는 p 사용 + if (p >= s) //끝까지 다 만들면 끝 + { + answer.push_back(c); + return answer; + } + } + answer.push_back(c); + } + for (i = p; i < s; ++i) + progresses[i] += speeds[i]; //개발 진행 + } +} \ No newline at end of file diff --git "a/Week2/BlueStaxks/2-4 \353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" "b/Week2/BlueStaxks/2-4 \353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" new file mode 100644 index 0000000..97d5606 --- /dev/null +++ "b/Week2/BlueStaxks/2-4 \353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" @@ -0,0 +1,73 @@ +#include +#include +#include +using namespace std; +map m; //긴 배열에 겹치지 않게 트럭을 배치하는 느낌 +int solution(int bridge_length, int weight, vector truck_weights) +{ + int current_truck_count = 0, current_weight = 0, time, truck_index = 0; + queue q; + for (time = bridge_length + 1; ;) //time은 다리를 다 건너는 시간으로 맞춰져 있음 + { + if (current_truck_count < bridge_length && current_weight + truck_weights[truck_index] <= weight) //트럭 올리기 가능 + { + if (truck_index == truck_weights.size() - 1) //마지막 트럭이 들어오면 리턴 //어차피 마지막 트럭에 의해 최종 시간이 결정됨 + return time; + m[time] = truck_weights[truck_index]; + current_weight += truck_weights[truck_index]; //총 무게 + current_truck_count++; //다리 위 트럭 수 + q.push(time); //m에서의 트럭 위치를 Queue에 입력 + time++; //트럭 들어갔으니 1초 뒤로 + truck_index++; //다음 트럭으로 + } + else + { + current_weight -= m[q.front()]; + time = q.front() + bridge_length; //트럭을 올릴 수 없다면 다리에 있는 트럭을 빼야됨. 빼자마자 들어가야 되기 때문에 그에 맞는 time 설정 + q.pop(); + current_truck_count--; + } + if(!q.empty()) + while (q.front() + bridge_length <= time) //다리 길이보다 앞에 있는 애들 없애기 == 이미 다리 건넌 애들 없애기 + { + current_weight -= m[q.front()]; + q.pop(); + current_truck_count--; + if (q.empty()) + break; + } + } +} + + + +#include +int main() +{ + vector v(5); + v[0] = 7; v[1] = 4; v[2] = 5; v[3] = 4; v[4] = 5; + cout << solution(2, 10, v); //8 +} + +/* + + m map : key = time, value = 트럭 무게 //m이라는 배열이 시간을 key로 해서 길게 있고 그 위에 트럭을 적절히 배치한 뒤 다리를 움직이는 것이라 생각하면 쉬움 + + time = brodge_length + 1 + while(1) + 만약 다리에 다음 트럭이 올라갈 수 있다면 + { + 만약 다음 트럭이 마지막 트럭이라면 + time 리턴 //유일한 종료 조건 + + Queue에 그 트럭의 다리 통과(끝) 시간 push + 트럭 들어갔으니 time 1추가 + } + else //여기로 왔다는 것은 다리에 트럭을 못올린다는 거니까 다리에서 트럭을 빼야됨 + { + Queue 가장 앞 트럭 빼기 + time 에 가장 앞 트럭의 다리 통과(끝) 시간 입력 + } + 이미 다리를 다 통과한 트럭을 Queue에서 제거 + +*/ \ No newline at end of file diff --git "a/Week2/BlueStaxks/2-5 \355\212\234\355\224\214.cpp" "b/Week2/BlueStaxks/2-5 \355\212\234\355\224\214.cpp" new file mode 100644 index 0000000..712f64f --- /dev/null +++ "b/Week2/BlueStaxks/2-5 \355\212\234\355\224\214.cpp" @@ -0,0 +1,70 @@ +#include +#include +#include +using namespace std; +int vs = 0; +vector exN(string& s) //문자열에서 숫자 뽑기 +{ + vector v; + int n = 0; + for (int i = 0; i < s.length(); ++i) + { + if ('0' <= s[i] && s[i] <= '9') + { + n *= 10; + n += s[i] - '0'; + } + else //string s 마지막은 반드시 '}'이기 때문에 마지막 수를 따로 처리할 필요 없음 + { + v.push_back(n); + n = 0; + } + } + return v; +} +vector> check(string& s) +{ + vector> v(501); + int i, p1, p2; + string t; + for (i = 1; i < s.length() - 1; ++i) + { + p1 = s.find("{", i); + if (p1 == string::npos) break; + p2 = s.find("}", p1 + 1); + i = p2; //이러면 한 묶음을 체크하고 다음 묶음으로 바로 넘어감 + t = s.substr(p1 + 1, p2 - p1); //t는 한 묶음이 되고 + vector vt = exN(t); //그 묶음에 있는 수들이 vt에 들어감 + sort(vt.begin(), vt.end()); //차집합 연산을 위해 미리 sort + v[vt.size()] = vt; + vs < vt.size() ? vs = vt.size() : 0; //vs는 원소 개수 + } + for (i = 500; i > vs; --i) + v.pop_back(); //쓸데 없는 벡터 지우기 + return v; +} +vector solution(string s) +{ + vector> v = check(s); //v[0]엔 없고 v[1]부터 있고 []안의 수가 사이즈임 //1개짜리, 2개짜리를 봤을 때 2개짜리에서 새로 생긴 수가 더 나중에 나오는 수임 + vector r; + vector::iterator it; //차집합 과정에 필요 + int i; + r.push_back(v[1][0]); //첫 수 입력 + for (i = 1; i < vs; ++i) + { + vector t(v[i + 1].size() + v[i].size()); + it = set_difference(v[i + 1].begin(), v[i + 1].end(), v[i].begin(), v[i].end(), t.begin()); //이러면 t에 v[i+1],v[i]의 차집합이 들어감 + r.push_back(t[0]); //차집합의 원소 개수는 어차피 1개니까 t를 resize하지 않고 [0]으로 바로 참조 + } + return r; +} + + +#include +int main() +{ + vector r = solution("{{2},{2,1},{2,1,3},{2,1,3,4}}"); + for (int i = 0; i < r.size(); ++i) + printf("%d ", r[i]); + return 0; +} diff --git "a/Week2/BlueStaxks/2-6 \354\234\204\354\236\245.cpp" "b/Week2/BlueStaxks/2-6 \354\234\204\354\236\245.cpp" new file mode 100644 index 0000000..dae0172 --- /dev/null +++ "b/Week2/BlueStaxks/2-6 \354\234\204\354\236\245.cpp" @@ -0,0 +1,21 @@ +#include +#include +#include +#include +using namespace std; +int solution(vector> clothes) +{ + int i, r = 1; + unordered_map m; + vector v; + for (i = 0; i < clothes.size(); ++i) + { + v.push_back(clothes[i][1]); + m[clothes[i][1]]++; //옷 종류당 몇개인지 체크 + } + sort(v.begin(), v.end()); //17번 줄의 중복 제거를 위해 sort가 필요함 + v.erase(unique(v.begin(), v.end()), v.end()); //v는 옷 종류를 담는 배열 + for (i = 0; i < v.size(); ++i) + r *= (m[v[i]] + 1); //경우의 수 연산 + return r - 1; //다 벗은 경우 제외, clothes가 하나도 없을 경우 자동으로 0 리턴(r이 처음엔 1이니까) +} diff --git "a/Week2/BlueStaxks/2-7 \354\227\220\353\224\224\355\204\260.cpp" "b/Week2/BlueStaxks/2-7 \354\227\220\353\224\224\355\204\260.cpp" new file mode 100644 index 0000000..57972fc --- /dev/null +++ "b/Week2/BlueStaxks/2-7 \354\227\220\353\224\224\355\204\260.cpp" @@ -0,0 +1,99 @@ +#include +#include +using namespace std; +int to_next[600005]; //여기서 0이 나오면 안됨 +int to_front[600005]; //one 스케일 //서로 역함수 느낌 +string s; //계속 사용할 문자열 +int cursor, synthetic_length; //제로 스케일 --> cursor 자체가 s의 몇 번쨰 (1부터) +void init() +{ + synthetic_length = s.length(); //synthetic_length는 s의 실제 길이 말고 편집에 의한 길이임. B를 한다고 해서 실제 s가 지워지진 않지만 synthetic_length는 1 작아짐 + for (int i = 0; i < synthetic_length; ++i) + { + to_next[i] = i + 1; //to_next[1]=2 --> 1번째 글자 뒤에 2번째 글자 //[]안의 수 번째보다 한 칸 뒤 위치를 나타냄 + to_front[i + 1] = i; //to_front[2]=1 --> 2번째 글자 앞엔 1번째 글자 //[]안의 수 번째보다 한 칸 앞 위치를 나타냄 + } + to_front[0] = 0; //연속된 L에 대응 +} +void doB() +{ + if (!to_next[cursor]) //cursor가 가장 마지막이면 + { + int t = to_front[cursor]; + to_next[t] = 0; //0으로 만들어야 D를 했을 때 정상적인 대응 가능 + to_front[cursor] = 0; + synthetic_length--; + cursor = t; + return; + } + int t = to_next[cursor]; + to_next[to_front[cursor]] = t; //1번 글자가 2번, 2번 글자가 3번을 가리킬 때, 1번 글자가 바로 3번을 가리키도록 변경하는 것 + to_front[t] = to_front[cursor]; //이러면 두 배열에서 cursor라는 값이 사라지면서 비게됨 + synthetic_length--; + cursor = to_front[cursor]; +} +void doP() +{ + char additional_char; + cin >> additional_char; + s += additional_char; + if (!to_next[cursor]) //맨 뒤에 넣는 경우 + { + to_next[cursor] = s.length(); + to_front[s.length()] = cursor; + synthetic_length++; + cursor = to_next[cursor]; + return; + } + int t = to_next[cursor]; + to_next[cursor] = s.length(); //길이가 3, 커서가 2번째 글자 오른쪽에 있는 경우에 P를 하면 string s 바로 뒤에 새 문자가 추가됨 + to_next[s.length()] = t; //그리고 2번 글자가 3번을 가리켰지만 2번 글자가 마지막 4번 글자를 가리키게 하고 4번 글자는 3번 글자를 가리키도록 함 + to_front[t] = s.length(); //이러면 나중에 재귀를 통해 올바른 순서대로 모두 출력할 수 있고, 문자열을 중간에 변경할 필요가 없어져서 속도가 빠름 + to_front[s.length()] = cursor; + synthetic_length++; + cursor = to_next[cursor]; +} +void print(int index, int printers_length) //재귀를 쓰기 때문에 따로 함수 사용 +{ + if (printers_length == synthetic_length) return; //printers_length가 제로 스케일이라 synthetic_length와 같아지면 그 전에 이미 끝난 + cout << s[index - 1]; //빠른 입출력 코드를 쓰면 printf를 못씀 + print(to_next[index], printers_length + 1); +} +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); //빠른 입출력 + int task_count, i; + char t; + cin >> s; + init(); + cursor = synthetic_length; + cin >> task_count; + for (i = 0; i < task_count; ++i) + { + cin >> t; + if (t == 'L') + cursor = to_front[cursor]; //안전 + if (t == 'D' && to_next[cursor]) //안전 장치 + cursor = to_next[cursor]; //한 칸 앞으로 커서가 이동 + if (t == 'B' && cursor) + doB(); + if (t == 'P') + doP(); + /*printf("-->"); + print(to_next[0], 0); + printf("\n 0 1 2 3 4 5 6 7 9\nto_next --> "); + for (int j = 0; j < 10; ++j) + printf("%d ", to_next[j]); + printf("\nto_front --> "); + for (int j = 0; j < 10; ++j) + printf("%d ", to_front[j]); + printf("\nfull --> "); + cout << s << "\n\n";*/ //중간 과정 확인 + } + print(to_next[0], 0);//출력은 제로 스케일로 // 첫 글자가 사라졌을 수도 있으므로 0부터 시작 + return 0; +} +// a b c d +//0 1 2 3 4 <-- cursor diff --git "a/Week3/BlueStaxks/3-1 \354\225\204\352\270\260\354\203\201\354\226\264 \354\235\230\354\202\254\354\275\224\353\223\234.cpp" "b/Week3/BlueStaxks/3-1 \354\225\204\352\270\260\354\203\201\354\226\264 \354\235\230\354\202\254\354\275\224\353\223\234.cpp" new file mode 100644 index 0000000..d55574b --- /dev/null +++ "b/Week3/BlueStaxks/3-1 \354\225\204\352\270\260\354\203\201\354\226\264 \354\235\230\354\202\254\354\275\224\353\223\234.cpp" @@ -0,0 +1,226 @@ +/* + + ---//전역 변수 설정 + + 지도 배열 선언(20 * 20 사이즈, 정수형, 이름 : map, 초기값 : 전부 0) + 시간 변수 선언(정수형, 이름 : time, 초기값 : 0) + 지도 크기 변수 선언(정수형, 이름 : map_size) + 상어 크기 변수 선언(정수형, 이름 : shark_size, 초기값 : 2) + 먹은 고기 변수 선언(정수형, 이름 : eaten_fish, 초기값 : 0) + 상어의 X 위치 변수 선언(정수형, 이름 : current_X) + 상어의 Y 위치 변수 선언(정수형, 이름 : current_Y) + 쉬운 BFS를 위한 X축 파라미터 배열 선언(4 사이즈, 이름 : dx, 초기값 : {0,-1,1,0} ) + 쉬운 BFS를 위한 Y축 파라미터 배열 선언(4 사이즈, 이름 : dy, 초기값 : {-1,0,0,1} ) + Queue 선언(정수 2개를 세트로 입력하는 pair형, 이름 : q) + + + ---//check 함수(정수 반환, int x와 int y를 매개변수로 입력받음) //프로그램이 시작될 때 85줄의 main함수가 가장 먼저 시작됨 //check함수는 불릴 때만 실행됨 + + 움직인 횟수 변수 선언(정수형, 이름 : movement, 초기값 : 0) + for문을 위한 변수 선언(정수형, 이름 : i) + 가장 위 왼쪽 먹이를 선택하기 위해 만드는 X축 변수 선언(정수형, 이름 : tx, 초기값 : 20) //지도가 0~19까지 있으므로 20으로 설정 + 가장 위 왼쪽 먹이를 선택하기 위해 만드는 Y축 변수 선언(정수형, 이름 : ty, 초기값 : 20) //지도가 0~19까지 있으므로 20으로 설정 + 움직였나 안움직였나를 체크하는 변수 선언(bool형, 이름 : moved, 초기값 : false) + + q를 초기화 + 지도에서 이미 간 곳을 체크하기 위한 배열 선언(20 * 20 사이즈, bool형, 이름 : hb, 초기값 : 전부 false) + + hb[x][y]에 true 입력 + q에 x,y를 pair로 push + + while (q가 비어있지 않는 동안) + { + q 크기 변수 선언(정수형, 이름 : s, 초기값 : q의 크기) + movement에 1 추가 + while (s가 0보다 클 동안) + { + s에 1 감소 + pair 변수 선언(둘 다 정수형, 이름 : a, 초기값 : q의 가장 앞 pair) + q의 가장 앞 pair를 pop + for(i = 0, i < 4; ++i) //i가 0부터 3이 될 때까지 반복하고 i는 각 반복때 마다 1씩 증가 + { + BFS용 임시 X축 변수 선언(정수형, 이름 : qx, 초기값 : a의 앞 정수 + dx의 i번째 정수) + BFS용 임시 Y축 변수 선언(정수형, 이름 : qy, 초기값 : a의 뒷 정수 + dy의 i번째 정수) + + if(qx < 0 이거나 qx >= map_size 이거나 qy < 0 이거나 qy >= map_size) //qx와 qy가 지도 밖으로 나가는 것을 방지함 + 여기서 바로 반복시작 //만약 i가 1일 때 이 if문에 걸리면 i가 2가된 상태로 42줄부터 다시 시작 + + if(0 < map[qx][qy] 이면서 map[qx][qy] < shark_size) //이 if문에 걸리면 map[qx][qy]위치에 상어가 먹을 수 있는 먹이가 있는 것 + { + if(qy < ty) //더 높으면 높은 것 선택 (y값은 작을 수록 위쪽임) + { + ty에 qy값 입력 + tx에 qx값 입력 + } + if(qy와 ty가 같으면서 qx가 tx보다 작으면) //높이가 같을 땐 왼쪽 먹이를 선택해야함 + tx에 qx값 입력 //y는 이미 같으므로 입력 불필요 + } + + if((hb[qx][qy]가 false) 이면서 ((map[qx][qy]가 0) 이거나 (map[qx][qy]가 shark_size와 같음))) //이러면 지나갈 수 있는 곳이라는 뜻 + { + hb[qx][qy]에 true 입력 + moved에 true 입력 + q에 qx,qy를 pair로 push + } + } + } + + if(tx가 20이 아니면서 ty도 20이 아님) + { + eaten_fish에 1 추가 + map[tx][ty]에 0 입력 //먹이 먹은 곳은 0으로 초기화 + current_X에 tx 입력 //상어의 X 위치 업데이트 + current_Y에 ty 입력 //상어의 Y 위치 업데이트 + time 값에 movement 값 추가 //상어의 생존 시간 추가 //34줄에서 movement만 늘리고 time을 늘리지 않는 이유는, 먹이가 없을 경우 움직일 수 없지만 먹이가 없는 것을 알기 위해 움직여야 하기 때문 + tx와 ty값 모두에 20 입력 + 1을 반환하고 함수 종료 + } + if(moved가 false) + 0을 반환하고 함수 종료 + moved에 false 입력 + } + + + + ---//main 함수(정수 반환) + + for문을 위한 변수 선언(정수형, 이름 : i) + for문을 위한 변수 선언(정수형, 이름 : j) + 먹을 물고기가 있는 지 나타내는 변수 선언(bool형, 이름 : p) + + map_size값 입력 받기(정수형) + + for (i = 0; i < map_size; ++i) + for (j = 0; j < map_size; ++j) + { + map[j][i]값 입력 받기(정수형) + if (map[j][i]이 9와 같음) //9는 상어 처음 위치 + { + current_X에 j 입력; + current_Y에 i 입력; + map[j][i]에 0 입력; //0으로 초기화 + } + } + + (무한 반복문) + { + p에 false 입력; + for (i = 0; i < map_size; ++i) + for (j = 0; j < map_size; ++j) + if (map[j][i] < shark_size 이면서 map[j][i] > 0) + p에 true 입력; //p가 ture면 아직 먹을 물고기가 있다는 뜻 + if ((p가 false) 이거나 (함수 check(current_X, current_Y)의 반환값이 0)) + { + time 출력 + 0을 반환하고 함수 종료 + } + if (eaten_fish가 shark_size와 같음) //자기만큼 먹으면 커짐 + { + shark_size에 1 추가 + eaten_fish에 0 입력; + } + } +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/* + +#include //queue를 쓰기 위한 헤더 +#include +using namespace std; //C++ 명령어를 위한 코드 +int map[20][20] = {}; +int time = 0, map_size, shark_size = 2, eaten_fish = 0, current_X, current_Y; +int dx[4] = { 0,-1,1,0 }; //BFS를 사방으로 쉽게 하는 법 +int dy[4] = { -1,0,0,1 }; +queue> q; //pair가 인자가 되는 queue 선언, 이름 : q +int check(int x, int y) +{ + int movement = 0, i, tx = 20, ty = 20; + q = queue>(); //q 초기화 + bool hb[20][20] = {}, moved = false; //이미 간 곳을 체크하기 위한 배열 + hb[x][y] = 1; + q.push({ x,y }); //x와 y를 pair로 q에 push + while (!q.empty()) //q가 비어있지 않는 동안 + { + int s = q.size(); //s = q에 남아있는 pair 개수 + movement++; + while (s--) + { + pair a = q.front(); //int a 하듯이 pair a //q.front()는 q의 가장 앞 인자를 참조함 + q.pop(); //q를 pop함(가장 앞 인자 삭제) + for (i = 0; i < 4; ++i) + { + int qx = a.first + dx[i]; //a의 앞 정수 + dx[i]라는 뜻 //x,y를 pair했다면 first 인자는 x, second 인자는 y가 됨 + int qy = a.second + dy[i]; + if (qx < 0 || qx >= map_size || qy < 0 || qy >= map_size) continue; //배열 밖이면 넘어감 + if (0 < map[qx][qy] && map[qx][qy] < shark_size) //이 조건을 만족하면 이미 가본 곳일 수가 없음 + { + if (qy < ty) //더 높으면 (y는 수가 작을 수록 높은 것) + { + ty = qy; + tx = qx; + } + if (qy == ty && qx < tx) //높이가 같으면 왼쪽꺼 + tx = qx; + } + if (!hb[qx][qy] && (map[qx][qy] == 0 || map[qx][qy] == shark_size)) //물고기를 먹은 것은 아니고 그냥 움직이는 것 + { + hb[qx][qy] = 1; + moved = true; + q.push({ qx, qy }); + } + } + } + if (tx != 20 && ty != 20) //tx ty는 상어의 이번 턴 최종 위치가 됨 //그리고 그 값이 20이 아니라면 물고기를 먹었다는 뜻임 + { + eaten_fish++; + map[tx][ty] = 0; + current_X = tx; + current_Y = ty; + time += movement; + tx = ty = 20; //tx ty를 20으로 설정하면 가장 오른쪽 아래 +1이 됨. 지도 밖을 벗어나는 것 + return 1; + } + if (!moved) //못움직였다면 끝 + return 0; + moved = false; + } +} +int main() +{ + int i, j; + bool p; + scanf("%d", &map_size); + for (i = 0; i < map_size; ++i) + for (j = 0; j < map_size; ++j) + { + scanf("%d", &map[j][i]); + if (map[j][i] == 9) //9는 상어 처음 위치 + { + current_X = j; + current_Y = i; + map[j][i] = 0; + } + } + while (1) + { + p = false; + for (i = 0; i < map_size; ++i) + for (j = 0; j < map_size; ++j) + if (map[j][i] < shark_size && map[j][i] > 0) + p = true; //p가 1이면 아직 먹을 물고기가 있다는 뜻 + if (!p || !check(current_X, current_Y)) //current_X, current_Y는 상어의 위치 + { + printf("%d", time); + return 0; + } + if (eaten_fish == shark_size) //자기만큼 먹으면 커짐 + { + shark_size++; + eaten_fish = 0; + } + } +} + +*/ \ No newline at end of file diff --git "a/Week3/BlueStaxks/3-1 \354\225\204\352\270\260\354\203\201\354\226\264.cpp" "b/Week3/BlueStaxks/3-1 \354\225\204\352\270\260\354\203\201\354\226\264.cpp" new file mode 100644 index 0000000..b1392ca --- /dev/null +++ "b/Week3/BlueStaxks/3-1 \354\225\204\352\270\260\354\203\201\354\226\264.cpp" @@ -0,0 +1,96 @@ +#include //queue를 쓰기 위한 헤더 +#include +using namespace std; //C++ 명령어를 위한 코드 +int map[20][20] = {}; +int time = 0, map_size, shark_size = 2, eaten_fish = 0, current_X, current_Y; +int dx[4] = { 0,-1,1,0 }; //BFS를 사방으로 쉽게 하는 법 +int dy[4] = { -1,0,0,1 }; +queue> q; //pair가 인자가 되는 queue 선언, 이름 : q +int check(int x, int y) +{ + int movement = 0, i, tx = 20, ty = 20; + q = queue>(); //q 초기화 + bool hb[20][20] = {}, moved = false; //이미 간 곳을 체크하기 위한 배열 + hb[x][y] = 1; + q.push({ x,y }); //x와 y를 pair로 q에 push + while (!q.empty()) //q가 비어있지 않는 동안 + { + int s = q.size(); //s = q에 남아있는 pair 개수 + movement++; + while (s--) + { + pair a = q.front(); //int a 하듯이 pair a //q.front()는 q의 가장 앞 인자를 참조함 + q.pop(); //q를 pop함(가장 앞 인자 삭제) + for (i = 0; i < 4; ++i) + { + int qx = a.first + dx[i]; //a의 앞 정수 + dx[i]라는 뜻 //x,y를 pair했다면 first 인자는 x, second 인자는 y가 됨 + int qy = a.second + dy[i]; + if (qx < 0 || qx >= map_size || qy < 0 || qy >= map_size) continue; //배열 밖이면 넘어감 + if (0 < map[qx][qy] && map[qx][qy] < shark_size) //이 조건을 만족하면 이미 가본 곳일 수가 없음 + { + if (qy < ty) //더 높으면 (y는 수가 작을 수록 높은 것) + { + ty = qy; + tx = qx; + } + if (qy == ty && qx < tx) //높이가 같으면 왼쪽꺼 + tx = qx; + } + if (!hb[qx][qy] && (map[qx][qy] == 0 || map[qx][qy] == shark_size)) //물고기를 먹은 것은 아니고 그냥 움직이는 것 + { + hb[qx][qy] = 1; + moved = true; + q.push({ qx, qy }); + } + } + } + if (tx != 20 && ty != 20) //tx ty는 상어의 이번 턴 최종 위치가 됨 //그리고 그 값이 20이 아니라면 물고기를 먹었다는 뜻임 + { + eaten_fish++; + map[tx][ty] = 0; + current_X = tx; + current_Y = ty; + time += movement; + tx = ty = 20; //tx ty를 20으로 설정하면 가장 오른쪽 아래 +1이 됨. 지도 밖을 벗어나는 것 + return 1; + } + if (!moved) //못움직였다면 끝 + return 0; + moved = false; + } +} +int main() +{ + int i, j; + bool p; + scanf("%d", &map_size); + for (i = 0; i < map_size; ++i) + for (j = 0; j < map_size; ++j) + { + scanf("%d", &map[j][i]); + if (map[j][i] == 9) //9는 상어 처음 위치 + { + current_X = j; + current_Y = i; + map[j][i] = 0; + } + } + while (1) + { + p = false; + for (i = 0; i < map_size; ++i) + for (j = 0; j < map_size; ++j) + if (map[j][i] < shark_size && map[j][i] > 0) + p = true; //p가 1이면 아직 먹을 물고기가 있다는 뜻 + if (!p || !check(current_X, current_Y)) //current_X, current_Y는 상어의 위치 + { + printf("%d", time); + return 0; + } + if (eaten_fish == shark_size) //자기만큼 먹으면 커짐 + { + shark_size++; + eaten_fish = 0; + } + } +} \ No newline at end of file diff --git "a/Week3/BlueStaxks/3-2 \354\264\214\354\210\230\352\263\204\354\202\260.cpp" "b/Week3/BlueStaxks/3-2 \354\264\214\354\210\230\352\263\204\354\202\260.cpp" new file mode 100644 index 0000000..8d73ee5 --- /dev/null +++ "b/Week3/BlueStaxks/3-2 \354\264\214\354\210\230\352\263\204\354\202\260.cpp" @@ -0,0 +1,46 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +using namespace std; +int main() +{ + int people, i, start, end, query, t1, t2, answer = 0, t; + vector v[100]; + scanf("%d\n%d %d\n%d", &people, &start, &end, &query); + for (i = 0; i < query; ++i) + { + scanf("%d %d", &t1, &t2); + v[t1 - 1].push_back(t2 - 1); //양방향 그래프 + v[t2 - 1].push_back(t1 - 1); + } + queue q; + q.push(start - 1); + bool hb[100] = {}; + hb[start - 1] = 1; //BFS 기본 세팅 + while (!q.empty()) + { + int s = q.size(); //촌수를 계산하기 위해 q의 크기만큼 도는 루프를 추가함 + while (s--) + { + t = q.front(); + if (t == end - 1) + { + printf("%d", answer); + return 0; + } + q.pop(); + for (i = 0; i < v[t].size(); ++i) + { + if (!hb[v[t][i]]) + { + q.push(v[t][i]); + hb[v[t][i]] = 1; + } + } + } + answer++; //위 루프에서 return이 안되면 촌수 ++ + } + printf("-1"); //촌수 연결 안되면 -1 + return 0; +} \ No newline at end of file diff --git a/Week3/BlueStaxks/3-3 DSLR.cpp b/Week3/BlueStaxks/3-3 DSLR.cpp new file mode 100644 index 0000000..93f620b --- /dev/null +++ b/Week3/BlueStaxks/3-3 DSLR.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +bool hb[10000]; +using namespace std; +void check() +{ + int a, b, t; //a에서 b로 가는 것 //t에 각 계산 결과 저장 + queue> q; + memset(hb, false, sizeof(hb)); //배열을 계속 재선언 하는 것 보다 memset이 훨씬 빠름 + cin >> a >> b; + q.push(make_pair(a, "")); + hb[a] = 1; + while (!q.empty()) + { + int n = q.front().first; + string s = q.front().second; + q.pop(); + t = n * 2; + if (t >= 10000) t %= 10000; + if (t == b) //이렇게 중간중간에 체크를 해주는 것이 q.front()를 pop할 때 한 번만 체크하는 것 보다 빠름. 백준 채점 기준으로 각각 2856 ms, 3696 ms 나옴 + { + cout << s << "D" << "\n"; + return; + } + if (!hb[t]) + { + q.push(make_pair(t, s + "D")); + hb[t] = 1; + } + t = n - 1; + if (t < 0) t = 9999; + if (t == b) + { + cout << s << "S" << "\n"; + return; + } + if (!hb[t]) + { + q.push(make_pair(t, s + "S")); + hb[t] = 1; + } + t = (n % 1000) * 10 + n / 1000; + if (t == b) + { + cout << s << "L" << "\n"; + return; + } + if (!hb[t]) + { + q.push(make_pair(t, s + "L")); + hb[t] = 1; + } + t = n / 10 + (n % 10) * 1000; + if (t == b) + { + cout << s << "R" << "\n"; + return; + } + if (!hb[t]) + { + q.push(make_pair(t, s + "R")); + hb[t] = 1; + } + } +} +int main() +{ + ios::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + int n; + cin >> n; + while (n--) check(); + return 0; +} \ No newline at end of file diff --git "a/Week3/BlueStaxks/3-4 \353\215\224\353\247\265\352\262\214.cpp" "b/Week3/BlueStaxks/3-4 \353\215\224\353\247\265\352\262\214.cpp" new file mode 100644 index 0000000..8211576 --- /dev/null +++ "b/Week3/BlueStaxks/3-4 \353\215\224\353\247\265\352\262\214.cpp" @@ -0,0 +1,23 @@ +#include +#include +#include +using namespace std; +priority_queue, greater> q; +int solution(vector scoville, int K) +{ + int i, a, b, count = 0; + for (i = 0; i < scoville.size(); ++i) + q.push(scoville[i]); // 작은 순으로 나오는 queue + while (q.size() >= 2 && q.top() < K) //q에 최소 2개는 있어야 더 맵게 만들 수 있음 + { + a = q.top(); + q.pop(); + b = q.top(); + q.pop(); + q.push(a + (b * 2)); + count++; + } + if (q.top() < K) //불가능하면 -1 + return -1; + return count; +} \ No newline at end of file diff --git "a/Week3/BlueStaxks/3-5 \354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" "b/Week3/BlueStaxks/3-5 \354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" new file mode 100644 index 0000000..ff40473 --- /dev/null +++ "b/Week3/BlueStaxks/3-5 \354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" @@ -0,0 +1,168 @@ +#include //queue를 안쓰는 방법 //programmers 채점 기준으로 두 방법 모두 0.02ms 정도 나오지만 뒷 방법이 결국 더 빠를 것임 +#include //이 방법은 while문을 너무 자주씀 +#include +#include +#include +#include +using namespace std; +unordered_map um; +vector solution(vector operations) +{ + vector v; + vector ni; + int i, t, array_length = 0, index, maxi, mini, max, min; + for (i = 0; i < operations.size(); ++i) + if (operations[i][0] == 'I') + v.push_back(stoi(operations[i].substr(operations[i].find(" ") + 1))); + sort(v.begin(), v.end()); //중간에 껴넣는게 안되는거니까 껴넣을 필요 없게 미리 필드 생성 + for (i = 0; i < v.size(); ++i) + um[v[i]] = i; //back 스케일 + vector va(operations.size(), false); + for (i = 0; i < operations.size(); ++i) + { + if (operations[i][0] == 'I') + { + t = stoi(operations[i].substr(operations[i].find(" ") + 1)); + index = um[t]; + if (index && v[index - 1] == t) //여기서 안걸리면 더이상 쓸 일 없는 index라는 뜻 + um[t]--; //중복 처리 + va[index] = true; + if (!array_length) + { + maxi = index; + mini = index; //둘 다 back 스케일 + } + else + { + if (index > maxi) maxi = index; + if (index < mini) mini = index; + } + array_length++; + } + else if(array_length) + { + if (operations[i][2] == '1') + { + va[maxi] = false; + if (array_length > 1) + while (maxi && !va[--maxi]); + } + else + { + va[mini] = false; + if (array_length > 1) + { + while (mini < va.size() - 1 && !va[++mini]); + t = va[mini]; + while (mini < va.size() - 1 && va[mini + 1] && v[mini + 1] == t) + mini++; //back 스케일 맞추기 + } + } + array_length--; + } + } + vector r; + if (array_length) + { + r.push_back(v[maxi]); + r.push_back(v[mini]); + return r; + } + else + { + r.push_back(0); + r.push_back(0); + return r; + } +} + + +//#include //정석 풀이 +//#include +//#include +//#include +//#include +//#include +//using namespace std; +//priority_queue> max_heap; +//priority_queue, vector>, greater>> min_heap; +//bool valid[1000000] = {}; //valid 배열로 두 queue를 싱크맞춤 //max_heap이나 min_heap에 있는 값은 위치는 달라도 같은 .second를 보유함 +//void sync_max_heap() +//{ +// while (!max_heap.empty() && !valid[max_heap.top().second]) +// max_heap.pop(); +//} +//void sync_min_heap() +//{ +// while (!min_heap.empty() && !valid[min_heap.top().second]) +// min_heap.pop(); +//} +//vector solution(vector operations) +//{ +// int i, num; +// for (i = 0; i < operations.size(); ++i) +// { +// if (operations[i][0] == 'I') +// { +// num = stoi(operations[i].substr(operations[i].find(" ") + 1)); +// min_heap.push({ num, i }); +// max_heap.push({ num, i }); +// valid[i] = true; +// } +// else +// { +// if (operations[i][2] == '1') +// { +// sync_max_heap(); +// if (!max_heap.empty()) +// { +// valid[max_heap.top().second] = false; //false로 바꾸기 전에 sync를 하기 때문에 true다음에 false가 나올 수 밖에 없고 둘이 섞이지 않음 +// max_heap.pop(); +// } +// } +// else +// { +// sync_min_heap(); +// if (!min_heap.empty()) +// { +// valid[min_heap.top().second] = false; +// min_heap.pop(); +// } +// } +// } +// } +// sync_min_heap(); +// sync_max_heap(); +// vector r; +// if (max_heap.empty()) +// { +// r.push_back(0); +// r.push_back(0); +// return r; +// } +// else +// { +// r.push_back(max_heap.top().first); +// r.push_back(min_heap.top().first); +// return r; +// } +//} + + +#include +int main() +{ + vector v; //["I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333"] + v.push_back("I -45"); + v.push_back("I 653"); + v.push_back("D 1"); + v.push_back("I -642"); + v.push_back("I 45"); + v.push_back("I 97"); + v.push_back("D 1"); + v.push_back("D -1"); + v.push_back("I 333"); + vector r = solution(v); + cout << r[0] << ' ' << r[1]; //333 -45 + return 0; +} \ No newline at end of file diff --git "a/Week3/BlueStaxks/3-6 \354\236\205\352\265\255\354\213\254\354\202\254.cpp" "b/Week3/BlueStaxks/3-6 \354\236\205\352\265\255\354\213\254\354\202\254.cpp" new file mode 100644 index 0000000..4b2f77e --- /dev/null +++ "b/Week3/BlueStaxks/3-6 \354\236\205\352\265\255\354\213\254\354\202\254.cpp" @@ -0,0 +1,78 @@ +//#include +//#include +//using namespace std; +//long long m[100000] = {}; +//long long solution(int n, vector times) //이분탐색 안쓴 방법 +//{ +// long long i, min, mini, max = 0, c = 0, d; +// double k = 0; +// for (i = 0; i < times.size(); ++i) +// k += 1.0 / (double)times[i]; //k는 가중치 총합 +// +// for (i = 0; i < times.size(); ++i) +// { +// d = floor((double)n * (1.0 / (double)times[i]) / k); //floor를 쓰지 않으면 c의 최종 값이 반드시 n이라는 것을 수학적으로 알 수 있음 +// c += d; +// m[i] += d * times[i]; +// } +// n -= c; +// +// while (n) +// { +// for (i = 0; i < times.size(); ++i) +// { +// if (!i) +// { +// min = m[0] + times[0]; +// mini = 0; +// } +// else if (m[i] + times[i] < min) +// { +// min = m[i] + times[i]; +// mini = i; +// } +// } +// m[mini] += times[mini]; +// n--; +// } +// for (i = 0; i < times.size(); ++i) +// if (max < m[i]) +// max = m[i]; +// return max; +//} +#include +#include +using namespace std; +long long solution(int n, vector times) //첫 방법에 이분탐색을 곁들인 +{ + long long i, st, en, mi, c; + double k = 0; + for (i = 0; i < times.size(); ++i) + k += 1.0 / (double)times[i]; //k는 가중치 총합 + en = 2 * floor((double)n / k); //첫 방법에서 알 수 있듯, n/k는 답과 근사한 값임 + st = floor((double)n / k) / 2; //st와 en을 이렇게 어느정도 계산한 뒤 시작하면 더 빠름 + while (st <= en) + { + mi = (st + en) / 2; + for (i = 0, c = 0; i < times.size(); ++i) + c += mi / times[i]; + if (c < n) + st = mi + 1; + else + en = mi - 1; + } + return st; //이렇게 이분탐색 하면 c==n인 경우가 여러개일 경우 그중 가장 작은 mid를 구할 수 있다. +} + + + + +#include +int main() +{ + vector t; + t.push_back(7); + t.push_back(10); + cout< +#include +#include +using namespace std; +int solution(int distance, vector rocks, int n) +{ + if (rocks.size() == n) return distance; + sort(rocks.begin(), rocks.end()); + int i, t, st = 0, en = distance, mi, delete_count; + while (st <= en) // 0 1 2 3 + { // one 스케일이지만 0이 있음 + delete_count = 0; + vector check(rocks.size(), false); + mi = (st + en) / 2; //mi길이만큼은 건너야 됨 //mi 최대한 크게 + t = 0; //범위 + for (i = 0; i < rocks.size(); ++i) + { + while (t < rocks[i] && rocks[i] < t + mi) //이래야 건너 뛸 애들 건너뜀 + { + check[i] = true; //지워야 하는 애들 true + delete_count++; + i++; + if (i == rocks.size()) break; + } + if (i < rocks.size()) t = rocks[i]; + } + i = rocks.size() - 1; + while (rocks[i] > distance - mi) // distance % mi가 항상 0이 되는 것이 아니므로, 거리상으로는 괜찮지만 도착지점과의 거리에서 안될 수도 있어서 체크 + { + if (!check[i]) delete_count++; //지워야 되는데 안지워진 애들 지우기 (실제로 check를 true로 바꿀 필요는 없음. 그냥 delete_count만 올리면 됨) + i--; + } + if (delete_count > n) + en = mi - 1; + else if (delete_count <= n) + st = mi + 1; + } + return en; //이런 식으로 이분탐색하면 같은 delete_count일 때 더 큰 mi를 구할 수 있음 +} + + + + +#include +int main() +{ + vector v(3); + v[0] = 4; v[1] = 8; v[2] = 11; //그냥 거리 가까운거를 막 지우면 이 경우 5라는 오답이 나옴 + cout< n) + end = mid - 1 + else + start = mid + 1 + + end 리턴 //이렇게 이분탐색하면 같은 '돌 지운 횟수'일 때 가장 큰 mid값은 end값이 됨 + + +*/ \ No newline at end of file diff --git "a/Week4/BlueStaxks/4-1 N\354\234\274\353\241\234\355\221\234\355\230\204.cpp" "b/Week4/BlueStaxks/4-1 N\354\234\274\353\241\234\355\221\234\355\230\204.cpp" new file mode 100644 index 0000000..f48882d --- /dev/null +++ "b/Week4/BlueStaxks/4-1 N\354\234\274\353\241\234\355\221\234\355\230\204.cpp" @@ -0,0 +1,49 @@ +#include +#include +using namespace std; +vector createV(vector v1, vector v2) +{ + vector r; + int i, j; + for (i = 0; i < v1.size(); ++i) + for (j = 0; j < v2.size(); ++j) + { + r.push_back(v1[i] + v2[j]); + r.push_back(v1[i] - v2[j]); + r.push_back(v2[j] - v1[i]); + if (v1[i] && v2[j]) + { + r.push_back(v1[i] * v2[j]); //0을 추가할 필요 없음 + r.push_back(v1[i] / v2[j]); + r.push_back(v2[j] / v1[i]); + } + } + return r; +} +int solution(int N, int number) +{ + if (N == number) return 1; //1개 + int i, j, t; + vector> v(9); + v[1].push_back(N); + for (i = 2; i <= 8; ++i) //i는 개수 (2면 N 2개로 만들 수 있는 수, v[2]엔 그 수들이 들어가 있는 것) + { + for (j = 1; j <= i / 2; ++j) //i가 5일 때를 예로 들자면 1+4, 2+3의 방법으로 5개짜리를 만들 수 있음 + { + vector vt = createV(v[j], v[i - j]); + v[i].insert(v[i].end(), vt.begin(), vt.end()); + } + for (j = 0, t = 0; j < i; ++j) + { + t *= 10; + t += N; + } // N이 5고 i가 3이면 555 추가 + v[i].push_back(t); + sort(v[i].begin(), v[i].end()); + v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end()); //중복 제거 + for (j = 0; j < v[i].size(); ++j) + if (v[i][j] == number) + return i; //있으면 i리턴 + } + return -1; //8을 넘어가면 -1 +} \ No newline at end of file diff --git "a/Week4/BlueStaxks/4-2 \354\240\225\354\210\230\354\202\274\352\260\201\355\230\225.cpp" "b/Week4/BlueStaxks/4-2 \354\240\225\354\210\230\354\202\274\352\260\201\355\230\225.cpp" new file mode 100644 index 0000000..d4981a5 --- /dev/null +++ "b/Week4/BlueStaxks/4-2 \354\240\225\354\210\230\354\202\274\352\260\201\355\230\225.cpp" @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int m[500][500] = {}; +int solution(vector> triangle) //아주 기본적인 DP문제 +{ + if (triangle.size() == 1) return triangle[0][0]; //높이가 1이면 뭐 할거 없이 리턴 + m[0][0] = triangle[0][0]; //초기값 + int i, j, ma = 0; + for (i = 1; i < triangle.size(); ++i) + for (j = 0; j < triangle[i].size(); ++j) + { + if (!j) //가장 왼쪽 + m[i][0] = m[i - 1][0] + triangle[i][0]; + else if(j == triangle[i].size() - 1) //가장 오른쪽 + m[i][j] = m[i - 1][j - 1] + triangle[i][j]; + else //중간 + m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + triangle[i][j]; //위 2개중 더 큰거 선택 + } + for (i = 0; i < triangle.back().size(); ++i) + if (m[triangle.size() - 1][i] > ma) ma = m[triangle.size() - 1][i]; + return ma; +} \ No newline at end of file diff --git "a/Week4/BlueStaxks/4-3 \355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" "b/Week4/BlueStaxks/4-3 \355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" new file mode 100644 index 0000000..e044d28 --- /dev/null +++ "b/Week4/BlueStaxks/4-3 \355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" @@ -0,0 +1,59 @@ +#include +#include +using namespace std; +string solution(string number, int k) +{ + int i, ptr = 0, tk = k, c = 0; //ptr은 one 스케일 + vector to_front(number.length() + 1, 0); + vector to_back(number.length() + 1, 0); //이거 참 내가 만들었지만 참 좋은 방법이구먼 + for (i = 0; i < to_back.size() - 1; ++i) //8ms도 안나오는 엄청난 속도!! + { + to_back[i] = i + 1; //여기서 0이 나오면 마지막이란 뜻 + to_front[i + 1] = i; + } + while (k) + { + while (1) + { + if (number[to_back[ptr] - 1] < number[to_back[to_back[ptr]] - 1]) // s to_back[s] to_back[to_back[s]] + { // 4 1 7 + int t = to_back[to_back[ptr]]; + to_back[ptr] = t; + to_front[t] = ptr; //1 -> 2 -> 3 --->> 1 -> 3 + k--; + break; + } + else + { + ptr = to_back[ptr]; + if (!ptr) //마지막 글자 + { + c = 1; + break; + } + } + } + if (c) //k가 남아있어도 나와야됨 + break; + ptr = to_front[ptr]; + } + string r = ""; + ptr = 0; + for (i = 0; i < number.length() - tk; ++i) //여기까지 왔는데 k가 남아있다면 그냥 뒤를 자르면 됨 + { + ptr = to_back[ptr]; + r += number[ptr - 1]; //one 스케일 보정 + } + return r; +} + + + + +#include +int main() +{ + string r = "4177252841"; //"775841" + cout< +#include +using namespace std; +int solution(vector people, int limit) //문제의 한정된 채점 데이터에 의해 정답이지만 엄밀하지 않은 풀이 +{ + sort(people.begin(), people.end()); + int i, j, r = 0; + for (i = people.size() - 1, j = 0; i >= j; i--, r++) //i는 무거운쪽, j는 가벼운쪽 시작 + if (people[i] + people[j] <= limit) + j++; //큰거 넣는데 작은거 껴들어 갈 수 있으면 끼워 넣는 방식 + return r; +} + +//#include +//#include +//using namespace std; +//int solution(vector people, int limit) //20 50 50 70 80 +//{ +// sort(people.begin(), people.end()); +// vector v(people.size(), false); //이미 태워 보냈으면 true 아니면 false +// int i, j, c, d = 0, st, mi, en; +// for (i = 0; i < people.size(); ++i, ++d) +// { +// if (v[i]) continue; +// c = people[i]; +// v[i] = true; +// st = i + 1; +// en = people.size() - 1; +// while (st <= en) //이분탐색을 곁들인 +// { +// mi = (st + en) / 2; +// if (people[mi] + c <= limit) //합쳐서 limit을 넘지 않는 최대값 구하기 +// st = mi + 1; +// else +// en = mi - 1; +// } +// for (j = en; j > i; --j) //0~i까지는 이미 다 보트 탐 +// { +// if (j >= people.size() || v[j] || c + people[j] > limit) continue; +// v[j] = true; +// break; +// } +// } +// return d; +//} + diff --git "a/Week4/BlueStaxks/4-5 \354\236\205\354\226\221\354\213\234\352\260\201(2).sql" "b/Week4/BlueStaxks/4-5 \354\236\205\354\226\221\354\213\234\352\260\201(2).sql" new file mode 100644 index 0000000..d99ce0f --- /dev/null +++ "b/Week4/BlueStaxks/4-5 \354\236\205\354\226\221\354\213\234\352\260\201(2).sql" @@ -0,0 +1,30 @@ +/* +WITH TEMP AS +( + SELECT 0 AS HOUR FROM DUAL UNION SELECT 1 AS HOUR FROM DUAL UNION SELECT 2 AS HOUR FROM DUAL UNION + SELECT 3 AS HOUR FROM DUAL UNION SELECT 4 AS HOUR FROM DUAL UNION SELECT 5 AS HOUR FROM DUAL UNION + SELECT 6 AS HOUR FROM DUAL UNION SELECT 7 AS HOUR FROM DUAL UNION SELECT 8 AS HOUR FROM DUAL UNION + SELECT 9 AS HOUR FROM DUAL UNION SELECT 10 AS HOUR FROM DUAL UNION SELECT 11 AS HOUR FROM DUAL UNION + SELECT 12 AS HOUR FROM DUAL UNION SELECT 13 AS HOUR FROM DUAL UNION SELECT 14 AS HOUR FROM DUAL UNION + SELECT 15 AS HOUR FROM DUAL UNION SELECT 16 AS HOUR FROM DUAL UNION SELECT 17 AS HOUR FROM DUAL UNION + SELECT 18 AS HOUR FROM DUAL UNION SELECT 19 AS HOUR FROM DUAL UNION SELECT 20 AS HOUR FROM DUAL UNION + SELECT 21 AS HOUR FROM DUAL UNION SELECT 22 AS HOUR FROM DUAL UNION SELECT 23 AS HOUR FROM DUAL +) +( + SELECT HOUR, 0 AS COUNT FROM TEMP + WHERE HOUR NOT IN (SELECT HOUR(DATETIME) FROM ANIMAL_OUTS) -- 그냥 GROUP BY를 해버리면 COUNT가 없는 경우가 아예 안나옴. 그러므로 억지로 COUNT 값이 0인 상태를 끼워넣음 +) +UNION +( + SELECT HOUR(DATETIME), COUNT(HOUR(DATETIME)) FROM ANIMAL_OUTS + GROUP BY HOUR(DATETIME) +) +ORDER BY HOUR +*/ + + + +--0으로 있는 테이블에 COUNT가 존재하는 실제 테이블을 LEFT JOIN하는 방식 +SELECT HOUR, ifnull(COUNT, 0) AS COUNT FROM (SELECT @N := @N + 1 AS HOUR FROM ANIMAL_OUTS, (SELECT @N := -1 FROM DUAL)NN LIMIT 24) AS A +LEFT JOIN (SELECT HOUR(DATETIME) AS HR, COUNT(*) AS COUNT FROM ANIMAL_OUTS GROUP BY HR) AS B +ON A.HOUR = B.HR diff --git "a/Week4/BlueStaxks/4-6 \355\227\244\353\271\204\354\234\240\354\240\200.sql" "b/Week4/BlueStaxks/4-6 \355\227\244\353\271\204\354\234\240\354\240\200.sql" new file mode 100644 index 0000000..25e88e5 --- /dev/null +++ "b/Week4/BlueStaxks/4-6 \355\227\244\353\271\204\354\234\240\354\240\200.sql" @@ -0,0 +1,2 @@ +SELECT ID, NAME, HOST_ID FROM PLACES +WHERE HOST_ID IN (SELECT HOST_ID FROM PLACES GROUP BY HOST_ID HAVING COUNT(HOST_ID) > 1) --헤비 유저를 뽑아내고 그 헤비유저들 SELECT \ No newline at end of file diff --git "a/Week4/BlueStaxks/4-7 \354\244\221\354\204\261\355\231\224.sql" "b/Week4/BlueStaxks/4-7 \354\244\221\354\204\261\355\231\224.sql" new file mode 100644 index 0000000..589eaea --- /dev/null +++ "b/Week4/BlueStaxks/4-7 \354\244\221\354\204\261\355\231\224.sql" @@ -0,0 +1,3 @@ +SELECT A.ANIMAL_ID, A.ANIMAL_TYPE, A.NAME FROM ANIMAL_INS A, ANIMAL_OUTS B +WHERE A.ANIMAL_ID = B.ANIMAL_ID AND A.SEX_UPON_INTAKE LIKE 'Intact%' AND (B.SEX_UPON_OUTCOME LIKE 'Spayed%' OR B.SEX_UPON_OUTCOME LIKE 'Neutered%') +ORDER BY A.ANIMAL_ID \ No newline at end of file diff --git "a/Week4/BlueStaxks/4-8 \354\236\245\353\260\224\352\265\254\353\213\210.sql" "b/Week4/BlueStaxks/4-8 \354\236\245\353\260\224\352\265\254\353\213\210.sql" new file mode 100644 index 0000000..41d5367 --- /dev/null +++ "b/Week4/BlueStaxks/4-8 \354\236\245\353\260\224\352\265\254\353\213\210.sql" @@ -0,0 +1,3 @@ +SELECT CART_ID FROM CART_PRODUCTS +WHERE CART_ID IN (SELECT CART_ID FROM CART_PRODUCTS WHERE NAME="Milk" AND CART_ID IN (SELECT CART_ID FROM CART_PRODUCTS WHERE NAME="Yogurt")) --2중 서브쿼리 +GROUP BY CART_ID \ No newline at end of file