鱼C论坛

 找回密码
 立即注册
查看: 3001|回复: 2

一个统计句子中出现多少次 ei 的问题。

[复制链接]
发表于 2019-10-15 11:35:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main()

{
    int n=0;
    bool inword = false;
    char ch;
    printf("请输入一段句子:");
    while(ch=getchar()!='#')
    {
        if (ch=='e')
        {
            inword =true;
            continue;
        }
        if (ch=='i'&&inword)
        {
            n++;
            printf("%d",n);
            continue;
        }
        inword = false;
    }
    printf("\n该句子一共出现了%d次ei",n);
   
        
    return 0;
}

求助鱼c的小伙伴们,救救孩子吧,哪里错了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-10-15 11:44:37 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>

  4. int main()

  5. {
  6.     int n=0;
  7.     bool inword = false;
  8.     char ch;
  9.     printf("请输入一段句子:");
  10.     while((ch=getchar())!='#')
  11.     {
  12.         if (ch=='e')
  13.         {
  14.             inword =true;
  15.             continue;
  16.         }
  17.         if (ch=='i'&&inword)
  18.         {
  19.             n++;
  20.         }
  21.         inword = false;
  22.         
  23.     }
  24.     printf("\n该句子一共出现了%d次ei",n);
  25.    
  26.         
  27.     return 0;
  28. }
复制代码


改出来了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-10-15 15:14:39 | 显示全部楼层
  while((ch=getchar())!='#') 哈哈
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 13:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表