diff options
| Commit | 8ff247409a63a804b6ffebe449e680c30338888d (patch) | |
|---|---|---|
| Author | 2023-04-05 11:28:43 +0300 | |
| Committer | 2023-04-05 11:28:43 +0300 | |
| Files | c9eef267c06318631b542ea71ffba2d3157b1977 | |
| uni-projects-8ff247409a63a804b6ffebe449e680c30338888d.tar uni-projects-8ff247409a63a804b6ffebe449e680c30338888d.tar.gz uni-projects-8ff247409a63a804b6ffebe449e680c30338888d.zip | ||
| Parent | 7ce1482f4aa4376adc2de1879d949a9da24b0b69 (diff) | |
[DAAP] Maycamp exercise
1 files changed, 31 insertions, 0 deletions
| -rw-r--r-- | Year 2/Design and analysis of algorithms/Practicum/Maycamp-175_Coaching_sort.cpp | 31 |
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 <stdio.h> + +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); +} |
