JIN_GAG 2023-09-06 19:16 采纳率: 50%
浏览 5
已结题

C++,退出代码-1073741819

第一行输入三个数字后enter,然后直接“进程已结束,退出代码-1073741819 (0xC0000005)
”,clang-tidy显示没有问题,这是哪里出问题了


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int nn,mm,q;
    cin >>nn >> mm >> q;
    struct Point
    {
        bool is_this_dark = false;
        bool is_this_crossing = false;
        int position = 0;
        Point * latter = nullptr;
        Point * former = nullptr;
    };
    struct Line
    {
        int position = 0;
        string on = "mango";
        Point * point = nullptr;
        Point * first_point = nullptr;
        Line * latter = nullptr;
        Line * former = nullptr;
    };
    class Light
    {
    public:
        Light(int n1,int m1)
        {
            this->n = n1;
            this->m = m1;
            this->hor_lines = &the_first_line_for_hor;
            this->ver_lines = &the_first_line_for_ver;
            this->first_hor_lines = this->hor_lines;
            this->first_ver_lines = this->ver_lines;
            this->hor_lines->point->former = nullptr;
            this->ver_lines->point->former = nullptr;
            this->hor_lines->point->latter = nullptr;
            this->ver_lines->point->latter = nullptr;
            this->hor_lines->first_point = this->hor_lines->point;
            this->ver_lines->first_point = this->ver_lines->point;
            this->hor_lines->latter = nullptr;
            this->ver_lines->latter = nullptr;
            this->hor_lines->former = nullptr;
            this->ver_lines->former = nullptr;
            this->temp_hor_lines = this->hor_lines;
            this->temp_ver_lines = this->ver_lines;
        }
        void Create_new_line()
        {
            cin >> direction;
            if (direction == standard)
            {

                cin >> hor_lines->position >> hor_lines->on;
                handle_hor_line(hor_lines->on == "on");
            }
            else
            {
                cin >> ver_lines->position >> ver_lines->on;
                handle_ver_line(ver_lines->on == "on");
                this->ver_lines->latter->former = this->ver_lines;
                this->ver_lines = this->ver_lines->latter;
            }
        }
        void handle_hor_line(bool is_this_on)
        {
            if (is_this_on)
            {
                while (this->temp_ver_lines->latter != nullptr)
                {
                    while(this->temp_ver_lines->point->latter != nullptr)
                    {
                        if (this->temp_ver_lines->point->position == hor_lines->position)
                        {
                            this->temp_ver_lines->point->is_this_dark = false;
                            this->temp_ver_lines->point->is_this_crossing = true;
                        }
                        this->temp_ver_lines->point = this->temp_ver_lines->point->latter;
                    }
                    this->temp_ver_lines->point = this->temp_ver_lines->first_point;
                }
                this->temp_ver_lines = first_ver_lines;
            }
            else
            {
                while (this->temp_hor_lines->latter != nullptr)        //循环检测是否与白线重合,若有则消除
                {
                    if (this->temp_hor_lines->position == this->hor_lines->position)
                    {
                        this->temp_hor_lines->former->latter = this->temp_hor_lines->latter;        //删除重合的白线
                        this->temp_hor_lines->latter->former = this->temp_hor_lines->former;
                    }
                    this->temp_hor_lines = this->temp_hor_lines->latter;
                }
                temp_hor_lines = first_hor_lines;
                while (this->temp_ver_lines->latter != nullptr)     //将经过的点调整为暗点并设置为未相交
                {
                    while(this->temp_ver_lines->point->latter != nullptr)
                    {
                        if(this->temp_ver_lines->point->position == this->hor_lines->position)
                        {
                            this->temp_ver_lines->point->is_this_crossing = false;
                            this->temp_ver_lines->point->is_this_dark = true;
                        }
                        this->temp_ver_lines->point = this->temp_ver_lines->point->latter;
                    }
                    this->temp_ver_lines->point = this->temp_ver_lines->first_point;
                    this->temp_ver_lines = this->temp_ver_lines->latter;
                }
                this->temp_ver_lines = this->first_ver_lines;
            }
        }
        void handle_ver_line(bool is_this_on)
        {
            if (is_this_on)
            {
                while (this->temp_hor_lines->latter != nullptr)
                {
                    while(this->temp_hor_lines->point->latter != nullptr)
                    {
                        if (this->temp_hor_lines->point->position == hor_lines->position)
                            this->temp_hor_lines->point->is_this_dark = false;
                        this->temp_hor_lines->point = this->temp_hor_lines->point->latter;
                    }
                    this->temp_hor_lines->point = this->temp_hor_lines->first_point;
                }
                this->temp_ver_lines = first_ver_lines;
            }
            else
            {
                while (this->temp_ver_lines->latter != nullptr)        //循环检测是否与白线重合,若有则消除
                {
                    if (this->temp_ver_lines->position == this->ver_lines->position)
                    {
                        this->temp_ver_lines->former->latter = this->temp_ver_lines->latter;        //删除重合的白线
                        this->temp_ver_lines->latter->former = this->temp_ver_lines->former;
                    }
                    this->temp_ver_lines = this->temp_ver_lines->latter;
                }
                this->temp_ver_lines = this->first_ver_lines;
                while (this->temp_hor_lines->latter != nullptr)
                {
                    while(this->temp_hor_lines->point->latter != nullptr)
                    {
                        if(this->temp_hor_lines->point->position == this->ver_lines->position)
                            this->temp_hor_lines->point->is_this_dark = true;
                        this->temp_hor_lines->point = this->temp_hor_lines->point->latter;
                    }
                    this->temp_hor_lines->point = this->temp_hor_lines->first_point;
                    this->temp_hor_lines = this->temp_hor_lines->latter;
                }
                this->temp_hor_lines = this->first_hor_lines;
            }
        }

        int calculate_and_report_lights()
        {
            while (this->temp_hor_lines->latter != nullptr)     //计算横线
            {
                this->on_lights_numbers += n;
                while (this->temp_hor_lines->point->latter != nullptr)
                {
                    if (this->temp_hor_lines->point->is_this_dark)
                        on_lights_numbers--;
                    this->temp_hor_lines->point = this->temp_hor_lines->point->latter;
                }
                this->temp_hor_lines->point = this->temp_hor_lines->first_point;
                this->temp_hor_lines = this->temp_hor_lines->latter;
            }
            this->temp_hor_lines = this->first_hor_lines;
            while (this->temp_ver_lines->latter != nullptr)     //计算横线
            {
                this->on_lights_numbers += m;
                while (this->temp_ver_lines->point->latter != nullptr)
                {
                    if (this->temp_ver_lines->point->is_this_dark && !this->temp_ver_lines->point->is_this_crossing)
                        on_lights_numbers--;
                    this->temp_ver_lines->point = this->temp_ver_lines->point->latter;
                }
                this->temp_ver_lines->point = this->temp_ver_lines->first_point;
                this->temp_ver_lines = this->temp_ver_lines->latter;
            }
            this->temp_ver_lines = this->first_ver_lines;
            return this->on_lights_numbers;
        }
        int time = 0;
    private:
        Line * hor_lines;       //横线
        Line * ver_lines;       //竖线
        Line * first_hor_lines;
        Line * first_ver_lines;
        Line * temp_hor_lines;
        Line * temp_ver_lines;
        Line the_first_line_for_hor;
        Line the_first_line_for_ver;
        int n,m;
        string direction;
        string standard = "row";
        int on_lights_numbers = 0;
    };
    Light lights(nn,mm);
    while (lights.time < q )
    {
        lights.Create_new_line();
        cout << lights.calculate_and_report_lights();
        lights.time++;
    }
    return 0;
}

  • 写回答

2条回答 默认 最新

  • 浪客 2023-09-06 19:23
    关注

    类和结构体声明放到main外面。
    构造李对结构体指针初始化,point没有初始化,使用里面的former就报错了。

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

报告相同问题?

问题事件

  • 系统已结题 9月14日
  • 已采纳回答 9月6日
  • 创建了问题 9月6日

悬赏问题

  • ¥50 安装华大九天aether
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证