m0_73608690 2022-10-02 22:09 采纳率: 100%
浏览 11
已结题

字符串匹配问题中出现的错误,无法运行

这个程序为什么无法运行?报错是count是不明确的符号

题目是字符串匹配,要求读入两个字符串a,b,判断前者是否是后者的字串,输出为前者在后者出现过几次

#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
using namespace std;

char a[50], b[50];
int la, lb, count;


void input_data()
{
    cin >> a;
    cin >> b;
}

void solve()
{
    bool match;
    la = strlen(a);
    lb = strlen(b);
    count = 0;
    for (int i = 0; i <= lb - la; i++)
    {
        match = true;
        for (int j = 0; j < la; j++)
        {
            if (a[j] != b[i + j])
            {
                match = false;
                break;
            }
            
        }
        if (match)
            count++;
    }
}

void output_data()
{
    if (count == 0)
        cout << "NONONO" << endl;
    else
        cout << count << endl;
}

int main()
{
    input_data();
    solve();
    output_data();
            
    return 0;

}


  • 写回答

3条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-10-03 01:43
    关注

    c++的库函数有关键字count ,冲突了呀,换个其他名字就行

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月11日
  • 已采纳回答 10月3日
  • 创建了问题 10月2日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来