Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4.  
  5. {
  6. int index = 0, combinationTimes = 0, total = 0;
  7. char userInput;
  8. char wordChar[index];
  9.  
  10. printf("please enter your input:n");
  11.  
  12. while ((userInput = getchar()) != '#')
  13. {
  14. if (userInput == 'n')
  15. continue;
  16.  
  17. wordChar[index] = userInput;
  18. index++;
  19. total++;
  20. }
  21.  
  22. for (index = 1; index < total; index++)
  23. {
  24. if (wordChar[index] == 'i')
  25. {
  26. if (wordChar[--index] == 'e')
  27. {
  28. combinationTimes++;
  29. ++index;
  30. }
  31. }
  32. }
  33.  
  34. printf("number of combination is: %d", combinationTimes);
  35.  
  36. return 0;
  37. }
  38.  
  39. dan@albatross $ gcc -Wall f.c -o f
  40. dan@albatross $ ./f
  41. please enter your input:
  42. bfiqwb23b r9pu3h2ru23r
  43. 9aisdbfuiasdf
  44. adsf#asdf
  45. #
  46. #
  47. #
  48. adsfadsfasdf
  49. 34324!
  50. ^C
  51.  
  52. for (index = 1; index < total; index++)
  53. {
  54. if (wordChar[index] == 'i' && wordChar[index - 1] == 'e')
  55. combinationTimes++;
  56. }
  57.  
  58. #define FALSE 0
  59. #define TRUE 1
  60.  
  61. int main(void)
  62. {
  63. int combinationTimes = 0;
  64. char userInput;
  65. short int last_e = FALSE;
  66.  
  67. printf("please enter your input:n");
  68.  
  69. while ((userInput = getchar()) != '#')
  70. {
  71. if (userInput == 'e')
  72. {
  73. last_e = TRUE;
  74. }
  75. else if (userInput == 'i' && last_e)
  76. {
  77. combinationTimes++;
  78. last_e = FALSE;
  79. }
  80. else
  81. {
  82. //this is important, otherwise combinations like 'ite' are counted
  83. last_e = FALSE;
  84. }
  85. }
  86.  
  87. printf("Number of combos: %dn", combinationTimes);
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement