fork(1) 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. free(x[i]);
  38. }
  39. }
  40. }
  41.  
  42. int B_S(char a[110],char b[110])
  43. {
  44. if(a[0]!='-' && b[0]=='-') return 1;
  45. else if(a[0]=='-' && b[0]!='-') return 3;
  46. else if(a[0]=='-' && b[0]=='-')
  47. {
  48. if(strlen(a)>strlen(b))
  49. return 3;
  50. else if(strlen(a)<strlen(b))
  51. return 1;
  52. else
  53. {
  54. int i;
  55. for(i=0 ; i<strlen(a) ; i++)
  56. {
  57. if(a[i]>b[i]) return 3;
  58. else if(a[i]<b[i]) return 1;
  59. }
  60. }
  61. return 3;
  62. }
  63. else
  64. {
  65. if(strlen(a)>strlen(b))
  66. return 1;
  67. else if(strlen(a)<strlen(b))
  68. return 3;
  69. else
  70. {
  71. int i;
  72. for(i=0 ; i<strlen(a) ; i++)
  73. {
  74. if(a[i]>b[i]) return 1;
  75. else if(a[i]<b[i]) return 3;
  76. }
  77. }
  78. return 3;
  79. }
  80. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
Standard output is empty