运行时错误:以下代码的运行时错误分段错误 (SIGSEGV)

时间:2021-06-23 17:00:09

标签: c++

我已经解决了gfg中的括号检查问题。当我使用自定义输入检查此代码时,它工作正常并且输出匹配。当我提交此代码时,它显示

<块引用>

运行时错误:运行时错误分段错误 (SIGSEGV)

    def draw(self, screen):
        super().draw(screen)

        if self.part == 1:
            screen.blit(self.record_text, (550, 20))
            screen.blit(self.main_image.image, (580, 280)) 
        else:
            # Second half 
            text2 = font.render('¿Qué has visto?',True, PURPLE)
            screen.blit(text2, (400,5))

            # Show all similar images
            cont = 0       
            
            for game_image in self.game_images:
                if cont < 4:
                    
                    game_image.draw(screen)
                cont += 1
            # We associate the correct rect to the correct image, to pass it later to the CORRECT Screen
            self.correct_image_rect = self.game_images[self.game_images.index(self.main_image)].rect

1 个答案:

答案 0 :(得分:3)

您在执行 s.top() 时没有检查 s 是否为空。您应该为此添加检查。

else if (!s.empty() && (x[i]==']'&& s.top()=='['|| x[i]==')'&& s.top()=='('||x[i]=='}'&& s.top()=='{'))
       s.pop();