算法原理:
判断相邻的两个字母是否连续可以通过他们的差值是否为1来判断
即 if(str[i]-str[i-1]==1)
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char str[100];
int i=1;
int count=0;
printf("Input a string.\n");
gets(str);
printf("The string you input is:%s\n",str);
while(str[i]!='\0')
{
if(str[i]-str[i-1]==1)
{
//如果相邻两个字母连续,则继续判断下一个字母是否连续
if(str[i]!=str[i+1]-1)
{
//如果该字母与前一字母不连续,则计数加1
count++;
}
}
i++;//指向下一个字母
}
printf("%d",count);
system("pause");
return 0;
}