Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void)
- {
- int index = 0, combinationTimes = 0, total = 0;
- char userInput;
- char wordChar[index];
- printf("please enter your input:n");
- while ((userInput = getchar()) != '#')
- {
- if (userInput == 'n')
- continue;
- wordChar[index] = userInput;
- index++;
- total++;
- }
- for (index = 1; index < total; index++)
- {
- if (wordChar[index] == 'i')
- {
- if (wordChar[--index] == 'e')
- {
- combinationTimes++;
- ++index;
- }
- }
- }
- printf("number of combination is: %d", combinationTimes);
- return 0;
- }
- dan@albatross $ gcc -Wall f.c -o f
- dan@albatross $ ./f
- please enter your input:
- bfiqwb23b r9pu3h2ru23r
- 9aisdbfuiasdf
- adsf#asdf
- #
- #
- #
- adsfadsfasdf
- 34324!
- ^C
- for (index = 1; index < total; index++)
- {
- if (wordChar[index] == 'i' && wordChar[index - 1] == 'e')
- combinationTimes++;
- }
- #define FALSE 0
- #define TRUE 1
- int main(void)
- {
- int combinationTimes = 0;
- char userInput;
- short int last_e = FALSE;
- printf("please enter your input:n");
- while ((userInput = getchar()) != '#')
- {
- if (userInput == 'e')
- {
- last_e = TRUE;
- }
- else if (userInput == 'i' && last_e)
- {
- combinationTimes++;
- last_e = FALSE;
- }
- else
- {
- //this is important, otherwise combinations like 'ite' are counted
- last_e = FALSE;
- }
- }
- printf("Number of combos: %dn", combinationTimes);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement