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