You are not logged in. Please login at www.codechef.com to post your questions!

×

I am getting a SIGABART error.. i cant find why.

include<iostream>

using namespace std; int main() {

int T;
cin>>T;
string s[T];int N[T],M[T];
for(int i=0;i<T;i++)
{
    cin>>s[i];cin>>N[i]>>M[i];

}
for(int i=0;i<T;i++)
{
    for(int j=N[i];j<M[T];j++)
    {
        string s1=s[i].substr(j,1);string s2=s[i].substr(j+1,1);
        if(s1.compare(s2)==-1){s[i].erase(j+1,1);s[i].insert(j,s2);}
    }
}
for(int i=0;i<T;i++)
{
    cout<<endl<<s[i];
}
return 0;

}

asked 03 Dec, 17:00

chaitu12789's gravatar image

0★chaitu12789
82
accept rate: 0%

thanku it should have been M[i]:)

(05 Dec, 04:06) chaitu127890★

welcome :D

(05 Dec, 13:26) l_returns4★

Idk what is the question but M[T] should be M[i] I guess(in condition of for loop)... If not.. share the question link.

link

answered 04 Dec, 10:40

l_returns's gravatar image

4★l_returns
1.3k19
accept rate: 26%

edited 04 Dec, 10:43

You are getting SIGABART because the value of M[T] goes beyond the string length and hence you cant compute substring of the string. In some Compilers, M[T] would be 0 by default. I checked on Codechef's Compiler it was random more than 32K and in your test case string length would be less, hence SIGABART. (Out of range). Mostly, instead of M[T], it would be M[i]. Just make sure N[i], M[i] it doesn't go beyond String length(s[i].size()).

link

answered 04 Dec, 11:11

black_truce's gravatar image

4★black_truce
814
accept rate: 33%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,646

question asked: 03 Dec, 17:00

question was seen: 99 times

last updated: 05 Dec, 13:26