Given an input char[]
I would like to find the number of discrete pairs in the string. So for an input of:
"dddd"
the output is 2 pairs
"ddd"
the output is 1 pair
"dd"
the output is 1 pair
"d"
the output is 0 pairs
The characters in each pair must be adjacent. For an input of "abca"
the output is still 0 because the 'a'
s are not adjacent.*
The goal is to find the total number of pairs in the string. So for an input of "aaxbb"
the output should be 2.*
For my input string of char a[] = "dppccddd"
there are 3 pairs of adjacent letters but my program's output is 4. How do I solve the problem?
int i = 0, count = 0, count1 = 0;
for (i = 0; i <= 6; i++)
{
if (a[i] == a[i + 1])
count++;
}
printf("%d", count);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…