fork download
  1. #include <stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6. static const size_t N = 5;
  7. static const size_t S_LEN = 5;
  8.  
  9. char str[N][S_LEN], temp[S_LEN];
  10. size_t i, last, count = 0;
  11.  
  12. int swapped = 1;
  13.  
  14. while (count < N && scanf("%4s", str[count]) == 1)
  15. ++count;
  16.  
  17. last = count;
  18. while (swapped && last--)
  19. {
  20. swapped = 0;
  21. for (i=0; i<last; ++i)
  22. {
  23. if(strcmp(str[i+1],str[i]) < 0)
  24. {
  25. strcpy(temp, str[i]);
  26. strcpy(str[i], str[i+1]);
  27. strcpy(str[i+1], temp);
  28. swapped = 1;
  29. }
  30. }
  31. }
  32.  
  33. for(i = 0; i< count; ++i)
  34. printf("%s\n", str[i]);
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 2012KB
stdin
abfg 
abcd 
xyzw 
pqrs 
orde
stdout
abcd
abfg
orde
pqrs
xyzw