From 8ff247409a63a804b6ffebe449e680c30338888d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 5 Apr 2023 11:28:43 +0300 Subject: [DAAP] Maycamp exercise --- .../Practicum/Maycamp-175_Coaching_sort.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Year 2/Design and analysis of algorithms/Practicum/Maycamp-175_Coaching_sort.cpp diff --git a/Year 2/Design and analysis of algorithms/Practicum/Maycamp-175_Coaching_sort.cpp b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-175_Coaching_sort.cpp new file mode 100644 index 0000000..f3d21a5 --- /dev/null +++ b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-175_Coaching_sort.cpp @@ -0,0 +1,31 @@ +#include + +int vals[200] = { 0 }; +char input[10000010] = { '\0' }; + +int main() { + int n; + scanf("%d", &n); + scanf("%s", input); + for (int i = 0; i < n; i++) { + vals[(int)input[i]]++; + } + + int ii = 0; + for (int i = '0'; i <= '9'; i++) { + while (vals[i]-- > 0) { + input[ii++] = i; + } + } + for (int i = 'a'; i <= 'z'; i++) { + while (vals[i]-- > 0) { + input[ii++] = i; + } + } + for (int i = 'A'; i <= 'Z'; i++) { + while (vals[i]-- > 0) { + input[ii++] = i; + } + } + printf("%s\n", input); +} -- cgit v1.3.1-23-gd82d