From b1624586a80e11b0f0c6ac520bec6cca3e991ae0 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Wed, 27 May 2026 19:55:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?2870=20:=20=EC=88=98=ED=95=99=EC=88=99?= =?UTF-8?q?=EC=A0=9C=20V1=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week2/BOJ2870/BOJ2870_V1.cpp | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/week2/BOJ2870/BOJ2870_V1.cpp diff --git a/src/week2/BOJ2870/BOJ2870_V1.cpp b/src/week2/BOJ2870/BOJ2870_V1.cpp new file mode 100644 index 0000000..ff75705 --- /dev/null +++ b/src/week2/BOJ2870/BOJ2870_V1.cpp @@ -0,0 +1,90 @@ +#include +using namespace std; +int N; +string extract_number_string(string s) { + bool is_pre_degit = false; + string ret = ""; + for (int i=0; i &elems) { + + auto st = 0; + auto end = s.find(delim); + string temp; + while (end != string::npos) { + temp = s.substr(st, end - st); + if (!temp.empty()) { + elems.push_back(temp); + } + st = end + 1; + end = s.find(delim, st); + } + + temp = s.substr(st); + if (!temp.empty()) + elems.push_back(temp); + +} + +bool cmp(string a, string b) { + + if (a.length() != b.length()) + return a.length() < b.length(); + + for (int i = 0; i < a.length(); i++) { + if (a[i] != b[i]) + return a[i] < b[i]; + } + + return false; +} + +void delete_zero(vector &elems) { + if (elems.empty()) + return; + for (int i=0; i 1 && elems[i][0] == '0') { + elems[i].erase(0, 1); + } + } +} +int main() { + + ios_base::sync_with_stdio(false); + + cin >> N; + vector num_str; + vector ret; + for (int i = 0; i < N; i++) { + string s; + cin >> s; + num_str.push_back(extract_number_string(s)); + } + + for (string s : num_str) { + split(s, ' ', ret); + } + + delete_zero(ret); + + sort(ret.begin(), ret.end(), cmp); + + for (string s : ret) { + cout << s << endl; + } + + return 0; +} \ No newline at end of file From 9b7915b6566519c0a3f6d0ac7a442863d1fec582 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Wed, 27 May 2026 20:25:15 +0900 Subject: [PATCH 2/2] =?UTF-8?q?2870=20:=20=EC=88=98=ED=95=99=EC=88=99?= =?UTF-8?q?=EC=A0=9C=20solve=20V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week2/BOJ2870/BOJ2870_V2.cpp | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/week2/BOJ2870/BOJ2870_V2.cpp diff --git a/src/week2/BOJ2870/BOJ2870_V2.cpp b/src/week2/BOJ2870/BOJ2870_V2.cpp new file mode 100644 index 0000000..12b7b36 --- /dev/null +++ b/src/week2/BOJ2870/BOJ2870_V2.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; +int N; +vector output; +string s, ret; +void run() { + while(true) { + if(ret.size() && ret.front() == '0') { + ret.erase(ret.begin()); + } else { + break; + } + } + + if(ret.size() == 0) + ret="0"; + + output.push_back(ret); + ret = ""; +} + +bool cmp(string a, string b) { + if (a.size() != b.size()) + return a.size() < b.size(); + return a < b; +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N; + + for (int i = 0; i < N; i++) { + cin >> s; + ret = ""; + for (int j=0; j= '0' && s[j] <= '9') { + ret += s[j]; + } else if (ret.size()){ + run(); + } + } + if (ret.size()) + run(); + + } + + sort(output.begin(), output.end(), cmp); + + for (string s : output) { + cout << s << "\n"; + } + return 0; +} \ No newline at end of file