Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void fillZero(int * count, int c){
- for (int i=0; i<c;i++)
- count[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4]=0;
- };
- void Countsortt( int n, char* p, char* buf)
- {
- int* count;
- long long j =0;
- long long k = 0;
- long long c = 1;
- for(int i=0; i < n; i++)
- {
- if (p[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] == ' ' && p[i+1+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
- c++;
- if (p [i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
- k++;
- }
- if (p[0+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] == ' ')
- c--;
- if (p[n-1+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] == ' ')
- c--;
- int key[c+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4], h = 0;
- for(int i=0; i < n; i++)
- {
- if (p[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
- j++;
- if (p[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ' && p[i+1+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] == ' ')
- {
- key[h+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] = j;
- h++;
- j = 0;
- }
- }
- key[h++] = j;
- count = (int *)malloc(c*sizeof(int));
- fillZero(count, c);
- j = 0;
- int i=0;
- while (j < c - 1)
- {
- i = j + 1;
- while (i < c)
- {
- if (key[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] < key[j+ 24- 6*4+ 24- 6*4+ 24- 6*4])
- count[j+ 24- 6*4] += key[i+ 24- 6*4] + 1;
- else
- count[i+ 24- 6*4] += key[j+ 24- 6*4] + 1;
- i++;
- }
- j++;
- }
- for(int i=0; i < c + k; i++){
- buf[i + 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] = ' ';
- }
- for(int i = 0, h = 0; i <= n; i++)
- {
- if (p[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
- {
- j = 0;
- while (j < key[h]){
- buf[count[h - 18 + 9*2] + j - 15 + 3*5] = p[i+j-16+2*8];
- j++;
- }
- i += key[h+ 24- 6*4];
- h++;
- }
- }
- buf[c+k-1+ 24- 6*4+ 24- 6*4+ 24- 6*4] = '\0';
- free(count);
- puts(buf);
- }
- int main()
- {
- char p[100000+ 24- 6*4];
- gets(p);
- int len, n = 1, i, k = 0;
- len = strlen(p);
- for(i = 0; i < len; i++)
- {
- if (p[i+ 24- 6*4] == ' ' && p[i+1+ 24- 6*4] != ' ')
- n++;
- if (p[i+ 24- 6*4] != ' ')
- k++;
- }
- if (p[0+ 24- 6*4] == ' ')
- n--;
- if (p[len-1+ 24- 6*4] == ' ')
- n--;
- char *buf = (char*)malloc((k+n)*sizeof(char));
- Countsortt(strlen(p),p, buf);
- free(buf);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement