Why do I get a SIGABRT?

#include
#define ll long long int
#include
#include
using namespace std;

int main()
{
ll test_case;
cin>>test_case;
ll temp=test_case;
ll k=0;
vectorg(temp);
while(test_case)
{
ll number;
ll c=0;
cin>>number;
vectorv(number);
map<ll,ll>m;
for(ll i=0;i<number;i++){
cin>>v[i];
m[v[i]]++ ;
if( m[v[i]]==1 &&v[i]!=0)
c++;
}
g[k++]=c;
}
for(ll i=0;i<temp;i++)
{
cout<<g[i]<<"\n";

}
return 0;
}

//why i am getting SIGABRT

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also - what Problem are you trying to solve? :slight_smile:

1 Like

Why this is getting SIGABRT Error? It works fine for single test case.
problem:LOSTMAX Problem - CodeChef
solution:CodeChef: Practical coding for everyone

[simon@simon-laptop][16:29:32]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling ashutosh_6500-LOSTMAX.cpp
+ g++ -std=c++14 ashutosh_6500-LOSTMAX.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
ashutosh_6500-LOSTMAX.cpp: In function ‘int main()’:
ashutosh_6500-LOSTMAX.cpp:17:23: warning: conversion to ‘std::__debug::multiset<int>::value_type {aka int}’ from ‘long long int’ may alter its value [-Wconversion]
             s.insert(x);
                       ^
ashutosh_6500-LOSTMAX.cpp:19:40: warning: conversion to ‘std::__debug::multiset<int>::key_type {aka int}’ from ‘std::__cxx1998::multiset<int, std::less<int>, std::allocator<int> >::size_type {aka long unsigned int}’ may alter its value [-Wconversion]
         s.erase(s.lower_bound(s.size() -1));
                               ~~~~~~~~~^~
ashutosh_6500-LOSTMAX.cpp:10:21: warning: unused variable ‘n’ [-Wunused-variable]
     long long int t,n,i,ma,x;
                     ^
ashutosh_6500-LOSTMAX.cpp:10:23: warning: unused variable ‘i’ [-Wunused-variable]
     long long int t,n,i,ma,x;
                       ^
ashutosh_6500-LOSTMAX.cpp:10:25: warning: unused variable ‘ma’ [-Wunused-variable]
     long long int t,n,i,ma,x;
                         ^~
+ set +x
Successful
[simon@simon-laptop][16:29:36]
[~/devel/hackerrank/otherpeoples]>echo "3                 
1 2 1
3 1 2 8
1 5 1 4 3 2" | ./a.out
/usr/include/c++/7/debug/multiset.h:328:
Error: attempt to erase from container with a past-the-end iterator.

Objects involved in the operation:
    sequence "this" @ 0x0x7ffe3dfb4f60 {
      type = std::__debug::multiset<int, std::less<int>, std::allocator<int> >;
    }
    iterator "__position" @ 0x0x7ffe3dfb4f00 {
      type = __gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<int>, std::__debug::multiset<int, std::less<int>, std::allocator<int> > > (mutable iterator);
      state = past-the-end;
      references sequence with type 'std::__debug::multiset<int, std::less<int>, std::allocator<int> >' @ 0x0x7ffe3dfb4f60
    }
Aborted (core dumped)
5 Likes

Ohhh.Thanks :+1: :+1:

1 Like

CHECKOUT this c++ code CodeChef: Practical coding for everyone getting error

int *ar = new int(N);

creates a single int, with value N, on the heap. You probably meant:

int *ar = new int[N];

(yet another reason to use vectors :))

4 Likes

thanks , well i got that my self by trail and error . and now i am stuck again as the answer is wrong CodeChef: Practical coding for everyone

1 Like

Here’s a random test input for which your solution fails:

1
5 5 3 4 2 58 72 72
-65 -64 -61 -29 92
2 Likes

I am getting SIGABRT i tried a lot of different ways to fix still i cant fix it
#include
#include
#include
#include
#include

using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
long long t,n,k,l;
cin>>t;
map<long long,long long>player;

while(t--){
	player.clear();
	cin>>n>>k>>l;
	if((n-k)==l){
		cout<<-1<<endl;
		continue;
	}
	vector<long long> vi(n);
	
	for(int i=1;i<=k;i++){
		vi[i]=i;
		player[i]++;
		
	}
	int p=k+1;
	for(int i=p;i<=n;i++){
		for(int j=1;j<=k;j++){
		if(player[j]<l && (i!=j+1) ){
			vi[i]=j;
		
		}
		
	}

}
	for(int i=1;i<=vi.size();i++){
		
		cout<<vi[i]<<" ";
	}
	cout<<endl;
}

}

Why do I get a SIGABRT here?

https://www.codechef.com/viewsolution/39177937

Why do I get SIGABRT
https://www.codechef.com/viewsolution/39714005

Here’s your solution, just copy pasted from your submission.
I guess I found the error.
You are trying to access invalid memory location. (Mentioned ‘here’ as a comment).

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int i,n,k,c=0;
        cin >> n >> k;
        string s[k+1]; int a[k+1]={0};
        fflush(stdin);
        for(i=1;i<=k;i++)
            getline(cin,s[i]);
       for(i=1;i<=k;i++){
            if(s[i]== "CLOSEALL"){
                a[k+1]={0}; //here
                cout << 0 << endl;
            }
            else {
                if(a[stoi(s[i].substr(6,7))]==0){
                a[stoi(s[i].substr(6,7))]=1;
                ++c;
                }
                else{
                a[stoi(s[i].substr(6,7))]=0;
                --c;
                    }
                if(c<0)  c=0;
                cout << c << endl;
            } 
        }
    return 0;
}

1 Like

I tried to run it by commenting that part and I still get the error.
In that part I am just Initalizing. Here is the more elaborate error
“terminate called after throwing an instance of ‘std::out_of_range’
what(): basic_string::substr: __pos (which is 6) > this->size() (which is 0)”.

thanks bro

Thank you

why do i get SIGABART here ? the code works really fine when executed on other C++ IDEs.

https://www.codechef.com/viewsolution/42918638

https://www.codechef.com/viewsolution/44470563
why my solution is not accepting just only throwing SIGABRT error.please help.

That’s a WA, not a SIGABRT.

Are you trying to “Run” without Providing “Custom Input”?

1 Like

#include
using namespace std;
//&& s.find(str) != -1
//static const size_type npos = -1;
int main() {
int t;
cin>>t;
//fflush(stdin);
string out[t];
for(int i = 0; i < t; i++){
int n, k;
cin>>n>>k;
//fflush(stdin);
char str[k] = {’\0’};
for(int j = 0; j < k; j++){
str[j] = ‘*’;
//cout<<j<<endl;
}
str[k] = ‘\0’;
cout<<str;
string s;
cin>>s;
fflush(stdin);
if(s.find(str) == string::npos){
out[i] = “NO”;
//cout<<s.find(str)<<endl;
}
else{
out[i] = “YES”;
//cout<<s.find(str)<<endl;
}
}
for(int i = 0; i < t; i++){
cout<<out[i]<<endl;
}
return 0;
}

Why am I getting SIGABRT here. PLEASE HELP