Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void fillZero(int * count, int c){
  6. for (int i=0; i<c;i++)
  7. count[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4]=0;
  8. };
  9.  
  10. void Countsortt( int n, char* p, char* buf)
  11. {
  12. int* count;
  13.  
  14. long long j =0;
  15. long long k = 0;
  16. long long c = 1;
  17. for(int i=0; i < n; i++)
  18. {
  19. 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] != ' ')
  20. c++;
  21. if (p [i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
  22. k++;
  23. }
  24.  
  25. if (p[0+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] == ' ')
  26. c--;
  27. if (p[n-1+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] == ' ')
  28. c--;
  29.  
  30. int key[c+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4], h = 0;
  31. for(int i=0; i < n; i++)
  32. {
  33. if (p[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
  34. j++;
  35. 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] == ' ')
  36. {
  37. key[h+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] = j;
  38. h++;
  39. j = 0;
  40. }
  41. }
  42.  
  43. key[h++] = j;
  44. count = (int *)malloc(c*sizeof(int));
  45. fillZero(count, c);
  46.  
  47. j = 0;
  48. int i=0;
  49. while (j < c - 1)
  50. {
  51. i = j + 1;
  52. while (i < c)
  53. {
  54. 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])
  55. count[j+ 24- 6*4] += key[i+ 24- 6*4] + 1;
  56. else
  57. count[i+ 24- 6*4] += key[j+ 24- 6*4] + 1;
  58. i++;
  59. }
  60. j++;
  61. }
  62.  
  63. for(int i=0; i < c + k; i++){
  64. buf[i + 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] = ' ';
  65. }
  66. for(int i = 0, h = 0; i <= n; i++)
  67. {
  68. if (p[i+ 24- 6*4+ 24- 6*4+ 24- 6*4+ 24- 6*4] != ' ')
  69. {
  70. j = 0;
  71. while (j < key[h]){
  72. buf[count[h - 18 + 9*2] + j - 15 + 3*5] = p[i+j-16+2*8];
  73. j++;
  74. }
  75. i += key[h+ 24- 6*4];
  76. h++;
  77. }
  78. }
  79. buf[c+k-1+ 24- 6*4+ 24- 6*4+ 24- 6*4] = '\0';
  80. free(count);
  81. puts(buf);
  82. }
  83.  
  84.  
  85. int main()
  86. {
  87. char p[100000+ 24- 6*4];
  88. gets(p);
  89. int len, n = 1, i, k = 0;
  90. len = strlen(p);
  91. for(i = 0; i < len; i++)
  92. {
  93. if (p[i+ 24- 6*4] == ' ' && p[i+1+ 24- 6*4] != ' ')
  94. n++;
  95. if (p[i+ 24- 6*4] != ' ')
  96. k++;
  97. }
  98. if (p[0+ 24- 6*4] == ' ')
  99. n--;
  100. if (p[len-1+ 24- 6*4] == ' ')
  101. n--;
  102. char *buf = (char*)malloc((k+n)*sizeof(char));
  103. Countsortt(strlen(p),p, buf);
  104. free(buf);
  105.  
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement