From 6ae28fe79a3f89ac1eb90afe2a966f1459a286ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Wed, 28 Feb 2024 02:36:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?6=EC=B0=A8=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YIM2UL2ET/README.md | 1 + .../6\354\260\250\354\213\234 - BOJ 1599.cpp" | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 "YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index dd45cb3..71c5f9a 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -7,4 +7,5 @@ | 3차시 | 2024.02.18 | 스택 | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/9) | | 4차시 | 2024.02.21 | 덱 | [BOJ 1021](https://www.acmicpc.net/problem/1021) | [BOJ 1021 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/12) | | 5차시 | 2024.02.21 | 큐 | [BOJ 1158](https://www.acmicpc.net/problem/1158) | [BOJ 1158 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/16) | +| 5차시 | 2024.02.21 | 정렬 | [BOJ 1599](https://www.acmicpc.net/problem/1599) | [BOJ 1599 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/21) | --- diff --git "a/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" "b/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" new file mode 100644 index 0000000..0950671 --- /dev/null +++ "b/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" @@ -0,0 +1,36 @@ +#include +#include + +std::string change_string(std::string str) +{ + int delay = 0; + std::string new_str = str; + for (int i = 0; i < str.size(); i++) { + if (str[i] == 'k') new_str[i-delay] = 'c'; + else if (str[i] > 'n') new_str[i-delay]++; + else if (str[i] == 'n' && i+1 < str.size() && str[i+1] == 'g') { + new_str.erase(new_str.begin() + (i++) - delay); + new_str[i - (++delay)] = 'o'; + } + } + return new_str; +} + +bool compare(std::string str1, std::string str2) +{ + return change_string(str1) < change_string(str2); +} + +int main(void) +{ + int n; + std::cin >> n; + + std::string str[n]; + for (int i = 0; i < n; i++) std::cin >> str[i]; + + std::sort(str, str+n, compare); + + for (int i = 0; i < n; i++) std::cout << str[i] << std::endl; + return 0; +} \ No newline at end of file From 0709c31ce2f352c07b944aa6b301e92085377240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:33:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../6\354\260\250\354\213\234 - BOJ 1599.cpp" | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git "a/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" "b/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" index 0950671..3b02e86 100644 --- "a/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" +++ "b/YIM2UL2ET/\354\240\225\353\240\254/6\354\260\250\354\213\234 - BOJ 1599.cpp" @@ -1,24 +1,24 @@ #include #include -std::string change_string(std::string str) +std::string translation(std::string min_str) { - int delay = 0; - std::string new_str = str; - for (int i = 0; i < str.size(); i++) { - if (str[i] == 'k') new_str[i-delay] = 'c'; - else if (str[i] > 'n') new_str[i-delay]++; - else if (str[i] == 'n' && i+1 < str.size() && str[i+1] == 'g') { - new_str.erase(new_str.begin() + (i++) - delay); - new_str[i - (++delay)] = 'o'; + int s_diff = 0; + std::string alpha_str = min_str; + for (int i = 0; i < min_str.size(); i++) { + if (min_str[i] == 'k') alpha_str[i-s_diff] = 'c'; + else if (min_str[i] > 'n') alpha_str[i-s_diff]++; + else if (min_str[i] == 'n' && i+1 < min_str.size() && min_str[i+1] == 'g') { + alpha_str.erase(alpha_str.begin() + (i++) - s_diff); + alpha_str[i - (++s_diff)] = 'o'; } } - return new_str; + return alpha_str; } bool compare(std::string str1, std::string str2) { - return change_string(str1) < change_string(str2); + return translation(str1) < translation(str2); } int main(void) @@ -26,11 +26,11 @@ int main(void) int n; std::cin >> n; - std::string str[n]; - for (int i = 0; i < n; i++) std::cin >> str[i]; + std::string min_str[n]; + for (int i = 0; i < n; i++) std::cin >> min_str[i]; - std::sort(str, str+n, compare); + std::sort(min_str, min_str+n, compare); - for (int i = 0; i < n; i++) std::cout << str[i] << std::endl; + for (int i = 0; i < n; i++) std::cout << min_str[i] << std::endl; return 0; } \ No newline at end of file