Let's say that a "pair" in a string is two instances of a char separated by a char. So in "AXA" the A's make a pair. Pai
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Let's say that a "pair" in a string is two instances of a char separated by a char. So in "AXA" the A's make a pair. Pai
Let's say that a "pair" in a string is two instances of a char separated by a char. So in "AXA" the A's make a pair. Pair's can overlap, so "AxAxA" contains 3 pairs -- 2 for A and 1 for x. Complete the function below to recursively compute the number of pairs in the given string: int countPairs (char *str) { } Test your function with the following strings. String Correct # of pairs "axa" || 1 "axax" 2 "axbx" || 1 "hi" 10 ["hihih" ||3 1111 "ihihhh"||3 NO 0 Il 11 a "aa" 0 "aaa" | 1 The recursive algorithm should not use any global variables.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!