|
| 1 | +--- |
| 2 | +title: Letter Pairs |
| 3 | +desc: Find the pairs of letters in a string |
| 4 | +class: COMP1511 |
| 5 | +difficulty: Easy |
| 6 | +--- |
| 7 | + |
| 8 | +A letter pair is two of the same character appearing next to each other in a string. E.g. in the string "terrifically" there are 2 letter pairs "rr" and "ll". |
| 9 | + |
| 10 | +Write a program that reads a lowercase string as input, counts and prints out the number of letter pairs in a word. |
| 11 | + |
| 12 | +## Assumptions |
| 13 | + |
| 14 | +- The input string will have length 2-64 and be made of only lowercase alphabetical characters (a-z). There will be no spaces or punctuation marks. |
| 15 | + |
| 16 | +- Two letter pairs of the same character, e.g. the two pairs of “ee” found in “beekeeper,” both count as separate letter pairs. |
| 17 | + |
| 18 | +- No letters will appear consecutively more than twice (e.g. "aaa" will not be an input). |
| 19 | + |
| 20 | + |
| 21 | +### Examples |
| 22 | + |
| 23 | +Input: |
| 24 | + |
| 25 | +```bash:~/1511-revision/letter_pairs |
| 26 | +$ dcc letter_pairs.c -o letter_pairs |
| 27 | +$ ./letter_pairs |
| 28 | +beekeeper |
| 29 | +``` |
| 30 | + |
| 31 | +Output: |
| 32 | + |
| 33 | +```bash:~/1511-revision/letter_pairs |
| 34 | +2 |
| 35 | +``` |
| 36 | + |
| 37 | +Explanation: The double letter pair “ee” occurs twice in this word. |
| 38 | + |
| 39 | +Input: |
| 40 | + |
| 41 | +```bash:~/1511-revision/letter_pairs |
| 42 | +$ dcc letter_pairs.c -o letter_pairs |
| 43 | +$ ./letter_pairs |
| 44 | +
|
| 45 | +``` |
| 46 | + |
| 47 | +Output: |
| 48 | + |
| 49 | +```bash:~/1511-revision/letter_pairs |
| 50 | +2 |
| 51 | +``` |
| 52 | + |
| 53 | +Explanation: The double letter pairs “ll” and “oo” each appear once in this word, so there are two double letter pairs. |
| 54 | + |
| 55 | +Input: |
| 56 | + |
| 57 | +```bash:~/1511-revision/letter_pairs |
| 58 | +$ dcc letter_pairs.c -o letter_pairs |
| 59 | +$ ./letter_pairs |
| 60 | +distinction |
| 61 | +``` |
| 62 | + |
| 63 | +Output: |
| 64 | + |
| 65 | +```bash:~/1511-revision/letter_pairs |
| 66 | +0 |
| 67 | +``` |
| 68 | + |
| 69 | +Explanation: There are no double letter pairs in this word - although some letters appear twice in the word, they do not appear consecutively, so they do not count as double letters. |
| 70 | + |
| 71 | +## CSE Autotest |
| 72 | + |
| 73 | +When you think your program is working, you can use CSE autotest to test your solution. |
| 74 | + |
| 75 | +```bash:~/1511-revision/letter_pairs:~ |
| 76 | +$ 1511 autotest letter_pairs |
| 77 | +``` |
| 78 | + |
| 79 | +## Solution |
| 80 | + |
| 81 | +You can view the solution code to this problem [here](https://github.com/csesoc/comp1511-revision-t1-2022/blob/master/solutions/double-letters/solution.c). |
0 commit comments