fork(1) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<ctype.h>
  5.  
  6. //#define print_input
  7.  
  8. int isvowel (char alphabet)
  9. {
  10. if (alphabet == 'A' || alphabet == 'E' || alphabet == 'I' || alphabet == 'O' || alphabet == 'U')
  11. return 1 ;
  12. else if (alphabet == 'a' || alphabet == 'e' || alphabet == 'i' || alphabet == 'o' || alphabet == 'u')
  13. return 1 ;
  14. else
  15. return 0 ;
  16.  
  17. }
  18.  
  19.  
  20. int compare(const void* ptr1 , const void* ptr2 )
  21. {
  22. char* word_1 = (char* )ptr1 ;
  23. char* word_2 = (char* )ptr2 ;
  24.  
  25. if (strlen(word_1) < strlen(word_2) )
  26. return -1 ;
  27. else if (strlen(word_1) > strlen(word_2))
  28. return 1 ;
  29.  
  30. int i ;
  31. int sum_1 = 0 ;
  32. int sum_2 = 0 ;
  33.  
  34. for(i = 0 ; i < strlen(word_1) ; i++)
  35. if (isupper(word_1[i]) )
  36. sum_1 ++ ;
  37.  
  38. for(i = 0 ; i < strlen(word_2) ; i++)
  39. if (isupper(word_2[i]) )
  40. sum_2 ++ ;
  41.  
  42. if (sum_1 < sum_2 )
  43. return -1 ;
  44. else if (sum_1 > sum_2)
  45. return 1 ;
  46.  
  47. int vowel_1 = 0 ;
  48. int vowel_2 = 0 ;
  49.  
  50. for(i = 0 ; i < strlen(word_1) ; i++)
  51. if (isvowel(word_1[i]) )
  52. vowel_1 ++ ;
  53.  
  54. for(i = 0 ; i < strlen(word_2) ; i++)
  55. if (isvowel(word_2[i]) )
  56. vowel_2 ++ ;
  57.  
  58. if (vowel_1 < vowel_2)
  59. return -1 ;
  60. else if (vowel_1 > vowel_2)
  61. return 1 ;
  62. else
  63. return (strcmp(word_1 , word_2)) ;
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. }
  71.  
  72. int main(void)
  73. {
  74. char input[100][80] ;
  75. int i = 0 ;
  76. int j ;
  77.  
  78. while (scanf("%s" , input[i]) != EOF)
  79. i++ ;
  80.  
  81. #ifdef print_input
  82. for(j = 0 ; j < i ; j++)
  83. printf("%s \n" , input[j]) ;
  84. #endif
  85.  
  86. qsort(input , i - 1 , sizeof(char) * 80 , compare) ;
  87.  
  88. printf("After sorted \n") ;
  89. for(j = 0 ; j < i ; j++)
  90. printf("%s \n" , input[j]) ;
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. return 0 ;
  98. }
  99.  
  100.  
  101.  
Success #stdin #stdout 0s 5488KB
stdin
This
Book
Keep
is
not
a
book
stdout
After sorted 
a 
is 
not 
This 
Book 
Keep 
book