Why do I get a SIGABRT?

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

why am I getting RE(SIGABRT) for this submission CodeChef: Practical coding for everyone…?

why is it showing SIGABRT error

#include <iostream>

using namespace std;

int T, M, N, count;
char raw_data[1000][1000];

int main()
{
    cin >> T;
    for (int t = 1; t <= T; t++)
    {
        // read data
        cin >> M >> N;
        for (int rw = 0; rw < 5 * M + 1; rw++)
        {
            for (int cl = 0; cl < 5 * N + 1; cl++)
            {
                cin >> raw_data[rw][cl];
            }
        }
        // data processing
        count = 0;
        int result[5] = {0, 0, 0, 0, 0};
        for (int cl = 1; cl < 5 * N + 1; cl += 5)
        {
            for (int rw = 1; rw < 5 * M + 1; rw++)
            {
                if (rw % 5 == 0)
                    continue;
                if (raw_data[rw][cl] == '*')
                    count++;
                if (rw % 4 == 0)
                {
                    result[count] = result[count] + 1;
                    count = 0;
                }
            }
        }
        // print data
        cout << "#" << t << " ";
        for (int pr = 0; pr < 5; pr++)
            cout << result[pr] << " ";
        cout << endl;
    }
    return 0;
}
help me please!