fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. int main()
  6. {
  7. int N;
  8. char *x[1000];
  9.  
  10. while(scanf("%d",&N)!= EOF)
  11. {
  12. int i;
  13. for(i=0 ; i<N ; i++){
  14. x[i]= (char*)malloc(sizeof(char)*110);
  15. scanf("%s",x[i]);
  16. }
  17. printf("\n");
  18.  
  19. int j,bubble; char *temp;
  20. for(i=N-1 ; i!=0 ; i--)
  21. {
  22. for(j=1 ; j<=i ; j++)
  23. {
  24. bubble=B_S(x[j-1],x[j]);
  25.  
  26. if(bubble==1)
  27. {
  28. temp = x[j];
  29. x[j] = x[j-1];
  30. x[j-1] = temp;
  31. }
  32. }
  33. }
  34.  
  35. for(i=0 ; i<N ; i++)
  36. printf("%s\n",x[i]);
  37. }
  38. }
  39.  
  40. int B_S(char a[110],char b[110])
  41. {
  42. if(a[0]!='-' && b[0]=='-') return 1;
  43. else if(a[0]=='-' && b[0]!='-') return 3;
  44. else if(a[0]=='-' && b[0]=='-')
  45. {
  46. if(strlen(a)>strlen(b))
  47. return 3;
  48. else if(strlen(a)<strlen(b))
  49. return 1;
  50. else
  51. {
  52. int i;
  53. for(i=0 ; i<strlen(a) ; i++)
  54. {
  55. if(a[i]>b[i]) return 3;
  56. else if(a[i]<b[i]) return 1;
  57. }
  58. }
  59. return 3;
  60. }
  61. else
  62. {
  63. if(strlen(a)>strlen(b))
  64. return 1;
  65. else if(strlen(a)<strlen(b))
  66. return 3;
  67. else
  68. {
  69. int i;
  70. for(i=0 ; i<strlen(a) ; i++)
  71. {
  72. if(a[i]>b[i]) return 1;
  73. else if(a[i]<b[i]) return 3;
  74. }
  75. }
  76. return 3;
  77. }
  78. }
  79.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
Standard output is empty