SPOJ - 运行时错误 SIGSEGV [英] SPOJ - Runtime error SIGSEGV

查看:53
本文介绍了SPOJ - 运行时错误 SIGSEGV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是中缀到后缀转换的实现,它在我的计算机上运行良好,但是当我在 SPOJ 上提交时,它给了我运行时错误 SIGSEGV,我是竞争性编程的新手,我无法处理此类错误.

Following is the implementation of infix to postfix conversion, it is working fine on my computer, but as I am submitting in on SPOJ it is giving me Runtime error SIGSEGV, I am new to competitive programming and I am unable to handle such type of errors.

#include <iostream>
#include <stack>
#include<string.h>
#include<ctype.h>
using namespace std;
int prec(char ch){
    switch(ch){
        case '^' : return 3;
                    break;
        case '*':
        case '/': return 2;
                break;
        case '+':
        case '-': return 1;
                break;
        default: return -1;
    }
}
void pti(char a[]){
    stack<int> post;
    int k = -1;
    for(int i = 0;i<strlen(a);i++){
        if(isalnum(a[i]))
            a[++k] = a[i];
        else if(a[i] == '(')
            post.push(a[i]);
        else if(a[i] == ')'){
            while(!post.empty() && post.top()!= '('){
                a[++k] = post.top();
                post.pop();
            }
            post.pop();
        }
        else {
            while(!post.empty() && prec(a[i]) <= prec(post.top())){
                a[++k] = post.top();
                post.pop();
            }
            post.push(a[i]);
        }
    }
    while(!post.empty()){
        a[++k] = post.top();
        post.pop();
    }
    a[++k] = '\0';
    cout<<a<<endl;
}
int main()
{
   int t;
   cin>>t;
   for(int i = 0;i<t;i++){
        char a[100];
        cin>>a;
        pti(a);
   }
}

推荐答案

你只需要使输入数组更长,例如大小为 1000 的获取 AC.

You just need to make the input array longer, e.g. a size of 1000 gets AC.

SIGSEGV 信号表示发生了分段错误,这基本上意味着您访问了不属于您的内存.

The SIGSEGV signal means a segmentation fault occured, which basically means you accessed memory that doesn't belong to you.

这篇关于SPOJ - 运行时错误 SIGSEGV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆