7章6题

来源:互联网 发布:scala 调用java 数组 编辑:程序博客网 时间:2024/05/16 05:28

编写一个程序读取输入,知道#,并报告序列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)

0 0
原创粉丝点击