编写一个程序读取输入,知道#,并报告序列ei出现的次数。
#include <stdio.h>
#include <stdlib.h>
#define STOP '#'
int main()
{
char c;
int count =0;
int temp;
while((c=getchar())!=STOP)
{
if(c=='e')
temp=1;
else if(c=='i'&&temp==1)
count++;
}
printf("ei=%d\n",count);
return 0;
}
这个程序的难点在于怎么记住前一个字符,当出现e是把temp置1,然后跟后一个字符相与,如果相符是ei,则count++;
else if(c=='i'&&temp==1)