Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
1 files changed, 31 insertions, 0 deletions
-rw-r--r--Year 2/Design and analysis of algorithms/Practicum/Maycamp-175_Coaching_sort.cpp31
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);
+}