Why do I get a SIGABRT?

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

question-: GCDQ Problem - CodeChef

my answer-:
https://www.codechef.com/viewsolution/45814516

why i am getting SIGABRT error here?

Pay attention to compiler warnings!

[simon@simon-laptop][20:43:06]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling satyabrata_6gb-GCDQ.cpp
+ g++ -std=c++14 satyabrata_6gb-GCDQ.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
satyabrata_6gb-GCDQ.cpp: In function ‘int main()’:
satyabrata_6gb-GCDQ.cpp:36:13: warning: ‘l’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    assert(l <= r);
             ^~
satyabrata_6gb-GCDQ.cpp:36:13: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
+ set +x
Successful
[simon@simon-laptop][20:43:11]
[~/devel/hackerrank/otherpeoples]>echo "1                     
3 3
2 6 9
1 1
2 2
2 3" | ./a.out
satyabrata_6gb-GCDQ.cpp:21:4: runtime error: index 3 out of bounds for type 'int [*]'
a.out: satyabrata_6gb-GCDQ.cpp:36: int main(): Assertion `l <= r' failed.
Aborted (core dumped)

@ssjgz may i know what compiler you use? these error diagnosis seems handy

All the information you need is there :slight_smile:

WHY MY CODE IS GETTING SIGABRT ERROR

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
	int n;
	cin>>n;
	vector<int> v(n);
	vector<pair<int,int>> rel(n);
	for(auto &i : v)
	{
		cin>>i;
	}
	vector<int> dup(v);
	sort(dup.begin(),dup.end());
	set<int> s(v.begin(),v.begin()+n);
	if(s.size() == 1)
	{
		for(int i = 1;i<= n ;i++)
		{
			cout<<v[0]+i<<" ";
		}
		cout<<"\n";
	}
	else
	{
		rel[0].first = dup[0];
		rel[0].second = 0;
		for(int i = 1;i<=n;i++){
			rel[i].first = dup[i];
			if( (i>1) and (dup[i]==dup[i-1])){
			//rel[i].first = dup[i];
			rel[i].second = rel[i-1].second-1;
			}
			else
			rel[i].second = dup[i]-1;
		}
		// for(auto i : rel)
		// {
		// cout<<i.first<<" "<<i.second<<" ";
		// cout<<"\n";
		// }
		for(int i = 0;i< n;i++)
		{
			cout<<rel[i].second<<" ";
		}
		cout<<"\n";
	}
}
}

I don’t know - what Problem are you trying to solve?

question-: Practice problem | MINVOTE

my answer-:
https://www.codechef.com/viewsolution/54439250

why my answer is getting a SIGABRT error?

Why am I getting SIGBART error in this code

Link:CodeChef: Practical coding for everyone

CODE:

using namespace std; 
typedef long long int ll;
int main() { 
    ios_base::sync_with_stdio(0); 
    int t;
    cin>>t;
    while(t--)
    {
     int m,x,pos;
     cin>>m>>x;
     vector<int>dp;
     cout<<"1 ";
     dp.push_back(0);
     dp.push_back(0);
     for(int j=2;j<=x;j++)
     { 
         vector<int> v;
     for(int i=0;i<j;i++)
     {
       v.push_back(i+1);
     } 
     pos=(m-1)%j;
     auto it=v.begin()+pos;
     v.erase(it);  
     cout<<v[dp[j-1]]<<" ";
     dp[j]=v[dp[j-1]]-1; 
     v.clear();
     }
     
     cout<<endl;
    }
    return 0; 
} ```

Out-of- bounds access with sample input:

[simon@simon-laptop][11:00:25]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling parth_2811-CIRCLEGAME.cpp
Executing command:
  g++ -std=c++17 parth_2811-CIRCLEGAME.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
Successful
[simon@simon-laptop][11:00:39]
[~/devel/hackerrank/otherpeoples]>echo "1                 
2 3
" | ./a.out
/usr/include/c++/9/debug/vector:427:
In function:
    std::__debug::vector<_Tp, _Allocator>::reference 
    std::__debug::vector<_Tp, 
    _Allocator>::operator[](std::__debug::vector<_Tp, 
    _Allocator>::size_type) [with _Tp = int; _Allocator = 
    std::allocator<int>; std::__debug::vector<_Tp, _Allocator>::reference = 
    int&; std::__debug::vector<_Tp, _Allocator>::size_type = long unsigned 
    int]

Error: attempt to subscript container with out-of-bounds index 2, but 
container only holds 2 elements.

Objects involved in the operation:
    sequence "this" @ 0x0x7ffd7b4ae240 {
      type = std::__debug::vector<int, std::allocator<int> >;
    }
Aborted (core dumped)

Here you need to look at the code. Without the code only by the name of this error, nothing can be said. It could be anything. Most often incorrect initialization or binding of elements.

#include

#include

using namespace std;

int main()

{

int T;

cin>>T;

while(T--){

    int N;

    string S;

    cin>>N>>S;

    int num = stoi(S);

    int XOR = 0;

    int temp;

    while(num){

        temp = num%10;

        XOR = XOR^temp;

        num/=10;

    }

   

    if(N%2){

        cout<<"YES"<<endl;

    }else{

        if(XOR==0){

            cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }

    }

   

}

return 0;

}

Why do I get a SIGABRT error here?

Why did I get this SIGABRT error here?
https://www.codechef.com/viewsolution/67272155

@kid_14_12 - you can ask this to the doubt solvers at this link for this problem - CodeChef: Practical coding for everyone