diff --git a/01/.vscode/tasks.json b/01/.vscode/tasks.json deleted file mode 100644 index d40e63e..0000000 --- a/01/.vscode/tasks.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "gcc compile", - "type": "shell", - "command": "gcc", - "options": { - "cwd": "${fileDirname}" - }, - "args": [ - "-o", - "${fileBasenameNoExtension}.exe", - "${file}" - ], - "group": "build", - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": true - } - }, - { - "label": "c execute", - "type": "shell", - "command": "./${fileBasenameNoExtension}.exe", - "group": { - "kind": "test", - "isDefault": true - }, - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": true - } - }, - { - "type": "cppbuild", - "label": "C/C++: g++.exe build active file", - "command": "C:\\MinGW\\bin\\g++.exe", - "args": [ - "-fdiagnostics-color=always", - "-g", - "${file}", - "-o", - "${fileDirname}\\${fileBasenameNoExtension}.exe" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ] -} \ No newline at end of file diff --git a/01/1431.c++ b/01/1431.c++ new file mode 100644 index 0000000..aacb53a --- /dev/null +++ b/01/1431.c++ @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +using namespace std; + +// 1. 각 시리얼 번호를 문자열로 받아 배열에 차례대로 저장한다. +// 2. sort의 비교함수를 사용하여 각 조건대로 swap 한다. + +bool cmp(string &a, string &b) +{ // 비교 함수 + int sum_a = 0, sum_b = 0; + for (int i = 0; i < a.length(); i++) + { // 문자열 내 모든 수 합 + if (isdigit(a[i])) + { + sum_a += a[i] - '0'; // char을 int로 + } + } + for (int i = 0; i < b.length(); i++) + { + if (isdigit(b[i])) + { + sum_b += b[i] - '0'; + } + } + if (a.length() != b.length()) + { // 1. 길이 비교 + return a.length() < b.length(); + } + else if (sum_a != sum_b) + { // 2. 문자열 내 숫자 합 비교 + return sum_a < sum_b; + } + else + { // 3. 사전순 비교 + return a < b; + } +} + +int main() +{ + // 입력 + int n; + cin >> n; + + vector v(n, ""); + + for (int i = 0; i < n; i++) + { + cin >> v[i]; + } + + // 연산 + sort(v.begin(), v.end(), cmp); + + // 출력 + for (int i = 0; i < n; i++) + { + cout << v[i] << "\n"; + } + return 0; +} \ No newline at end of file diff --git a/01/1431.cpp b/01/1431.cpp deleted file mode 100644 index 2ba252a..0000000 --- a/01/1431.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// 시리얼 번호 #1431 - -#include -#include -#include -#include -#include - -using namespace std; - -struct serial -{ - int len; - string input; -}; - -bool cmp(const serial &s1, const serial &s2) -{ - int s1sum = 0; - int s2sum = 0; - - if (s1.len != s2.len) - { - return s1.len < s2.len; - } - for (int i = 0; i < s1.len; i++) - { - if (s1.input[i] <= '9' && s1.input[i] >= '0') - { - s1sum += s1.input[i] - '0'; - } - if (s2.input[i] <= '9' && s2.input[i] >= '0') - { - s2sum += s2.input[i] - '0'; - } - } - if (s1sum != s2sum) - { - return s1sum < s2sum; - } - return s1.input < s2.input; -}; - -int main() -{ - int n; - cin >> n; - vector my_class; - my_class.assign(n, {}); - - for (int i = 0; i < n; i++) - { - cin >> my_class[i].input; - my_class[i].len = my_class[i].input.length(); - } - - sort(my_class.begin(), my_class.end(), cmp); - - for (int i = 0; i < n; i++) - { - cout << my_class[i].input << '\n'; - } - return 0; -} diff --git a/01/14425.c++ b/01/14425.c++ index e69de29..b3c3363 100644 --- a/01/14425.c++ +++ b/01/14425.c++ @@ -0,0 +1,100 @@ +#include +<<<<<<< Updated upstream +#include +#include +#include + +using namespace std; + +// 1. 각 시리얼 번호를 문자열로 받아 배열에 차례대로 저장한다. +// 2. sort의 비교함수를 사용하여 각 조건대로 swap 한다. + +bool cmp(string &a, string &b) +{ // 비교 함수 + int sum_a = 0, sum_b = 0; + for (int i = 0; i < a.length(); i++) + { // 문자열 내 모든 수 합 + if (isdigit(a[i])) + { + sum_a += a[i] - '0'; // char을 int로 + } + } + for (int i = 0; i < b.length(); i++) + { + if (isdigit(b[i])) + { + sum_b += b[i] - '0'; + } + } + if (a.length() != b.length()) + { // 1. 길이 비교 + return a.length() < b.length(); + } + else if (sum_a != sum_b) + { // 2. 문자열 내 숫자 합 비교 + return sum_a < sum_b; + } + else + { // 3. 사전순 비교 + return a < b; + } +} +======= +#include + +using namespace std; + +// 검색 시간 복잡도가 O(log2n)으로 낮은 Set을 사용한다. +>>>>>>> Stashed changes + +int main() +{ + // 입력 +<<<<<<< Updated upstream + int n; + cin >> n; + + vector v(n, ""); + + for (int i = 0; i < n; i++) + { + cin >> v[i]; + } + + // 연산 + sort(v.begin(), v.end(), cmp); + + // 출력 + for (int i = 0; i < n; i++) + { + cout << v[i] << "\n"; + } +======= + int n, m; + cin >> n >> m; + + set s; + while (n--) + { + string str; + cin >> str; + s.insert(str); + } + + // 연산 + int cnt = 0; + while (m--) + { + string input; + cin >> input; + if (s.find(input) != s.end()) + { + cnt++; + } + } + + // 출력 + cout << cnt; +>>>>>>> Stashed changes + return 0; +} \ No newline at end of file diff --git a/01/19636.c++ b/01/19636.c++ index e69de29..5aa8091 100644 --- a/01/19636.c++ +++ b/01/19636.c++ @@ -0,0 +1,69 @@ +#include +#include +#include + +using namespace std; + +tuple diet(int w0, int i0, int i, int a, int d, int t) +{ + // w: 몸무게, m: 기초대사량 + int w1 = w0, m1 = i0; // 기초대사량 변화 고려 안했을 때 + int w2 = w0, m2 = i0; // 기초대사량 변화 고려 했을 때 + + while (d--) + { + // 체중 += 일일 에너지 섭취량 - 일일 에너지 소비량 + // 일일 에너지 소비량 = 일일 기초 대사량 + 일일 활동 대사량 + w1 += i - (m1 + a); + w2 += i - (m2 + a); + + // 일일 기초대사량 변화 + if (abs(i - (m2 + a)) > t) + { //|일일 에너지 섭취량 - 일일 에너지 소비량| > 기초 대사량 변화 역치 + m2 += float(i - (m2 + a)) / 2.0; // 일일 기초 대사량 += ⌊(일일 에너지 섭취량 − 일일 에너지 소비량) / 2⌋ + } + } + return {w1, w2, m2}; +} +int main() +{ + int w0, i0, i, a; + int d, t; + int final_weight, final_meta; + // 입력 + cin >> w0 >> i0 >> t; + cin >> d >> i >> a; + + // 연산 + tuple tmp = diet(w0, i0, i, a, d, t); + int w1 = get<0>(tmp), m1 = i0; + int w2 = get<1>(tmp), m2 = get<2>(tmp); + + // 출력 + if (w1 <= 0) + { // 체중 0 이하인 경우 + cout << "Danger Diet\n"; + } + else + { + cout << w1 << " " << m1 << "\n"; + } + + if (w2 <= 0 || m2 <= 0) + { // 체중 or 일일 기초대사량 0 이하인 경우 + cout << "Danger Diet"; + } + else + { + cout << w2 << " " << m2 << " "; + if (m2 < i0) + { // 변화한 일일 기초대사량 < 기존 일일 기초대사량인 경우 요요 + cout << "YOYO"; + } + else + { + cout << "NO"; + } + } + return 0; +} \ No newline at end of file