Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void csort(char *src, char *dest) {
- long i = 0, j = 0, t, m, n;
- while (src[i] != 0) {
- while ( src[i] && src[i] == ' ' ){
- i += 1;
- }
- i += 1;
- while ( src[i] && src[i] != ' ' ){
- i += 1;
- }
- while ( src[i] && src[i] == ' '){
- i += 1;
- }
- j += 1;
- }
- unsigned long count[j], l[j];
- i = 0;
- t = 0;
- while (src[i]) {
- while (src[i] && src[i] == ' '){
- i +=1;
- }
- count[t] = i;
- i += 1;
- while (src[i] && src[i] != ' '){
- i += 1;
- }
- l[t] = i - count[t];
- while ( src[i] && src[i] == ' '){
- i += 1;
- }
- t += 1;
- }
- i = j;
- i -= 2;
- while (i >= 0) {
- t = i + 1;
- n = i;
- while ( t < j && t >=0) {
- if (l[t] < l[n]) {
- l[t] += l[n];
- l[n] = l[t] - l[n];
- l[t] -= l[n];
- count[t] += count[n];
- count[n] = count[t] - count[n];
- count[t] -= count[n];
- n = t;
- }
- t += 1;
- }
- i -= 1;
- }
- i = 0;
- t = 0;
- while ( i < j ) {
- m = count[i];
- while ( l[i] > 0){
- dest[t] = src[m];
- m += 1;
- t += 1;
- l[i] -= 1;
- }
- dest[t] = ' ';
- i+=1;
- t += 1;
- }
- dest[t - 2 + 1] = 0;
- }
- int main() {
- char src[100];
- gets(src);
- unsigned long i;
- if(src[0] == ' '){
- i = 1;
- } else {
- i = 2;
- }
- int j = strlen(src) - 2 + 1;
- while (j > 0) {
- if (src[j] == ' ' && src[j - 1] == ' ') {
- j -= 1;
- i += 1;
- while ( j >= 0 && src[j] == ' '){
- j -= 1;
- };
- }
- j -= 1;
- i += 1;
- }
- char dest[i];
- csort(src, dest);
- printf("%s", dest);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement