Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void csort(char *src, char *dest)
- {
- int dlin = strlen(src),i = 0,j = 1,t = 0;
- while(i < dlin) {
- if (src[i] == 32) {
- if (t == 0) {
- j = j +1;
- }
- ++t;
- ++i;
- }
- else {
- ++i;
- t = 0;
- }
- }
- int *a = (int*)malloc((j+2) * sizeof(int));
- int *counts = (int*)malloc((j+2) * sizeof(int));
- for(i = 0;i<j;i++) {
- a[i] = 0;
- counts[i] = 0;
- }
- int *b = (int*)malloc((j+2) * sizeof(int));
- i = 0;
- j = 0;
- t = 0;
- int m = 0;
- while(i < dlin) {
- if (src[i] == 32) {
- if (t == 0) {
- j = j +1;
- }
- m = 0;
- ++t;
- ++i;
- }
- else {
- a[j] = a[j] + 1;
- if (m == 0) {
- b[j] = i;
- }
- ++i;
- ++m;
- t = 0;
- }
- }
- int n = j+1;
- j = 0;
- while (j < n-1) {
- i = j+1;
- while (i<n) {
- if (a[i] < a[j]) {
- counts[j] += 1;
- }
- else {
- counts[i] += 1;
- }
- ++i;
- }
- ++j;
- }
- t = 0;
- int flag = 0;
- for(i = 0;i < n;i++) {
- j = 0;
- while(flag == 0) {
- if (counts[j] == i) {
- for(m = 0;m<a[j];m++) {
- dest[t+m] = src[b[j]+m];
- }
- t = t + m + 1;
- flag = 1;
- }
- ++j;
- }
- flag = 0;
- if (i < n - 1) {
- dest[t-1] = 32;
- }
- }
- free(a);
- free(counts);
- free(b);
- }
- int main()
- {
- char str[10000];
- char bufer[100];
- gets(str);
- csort(str,bufer);
- int b = 0;
- int g = strlen(bufer);
- for(int i = 0;i<g;i++) {
- printf("%c" , bufer[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement