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日

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算