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


can anyone tell me why I'm getting runtime error sigsev in this code for the problem CLEANUP in practice easy section


using namespace std; class job { int n,m,j[1000],chef[1000],assist[1000],c,a; public: void in_process() { cin>>n>>m; for(int i=0;i<n;i++) {="" j[i]="1;" }="" for(int="" i="0;i&lt;m;i++)" {="" int="" tem;="" cin="">>tem; j[tem]=0; } int l=0,k=0; for(int i=0;i<n;i++) { while(j[i]==0) i++; chef[l++]=i++; while(j[i]==0) i++; assist[k++]=i; } c=l; a=k; } void out() { if(c==0) cout<<" "; else for(int i=0;i<c;i++) cout<<chef[i]<<" "; cout<<endl; if(a==0) cout<<" "; else for(int i=0;i<a;i++) cout<<assist[i]<<" "; cout<<endl;


}; int main() { int t; cin>>t; job j[t]; for(int i=0;i<t;i++) j[t].in_process(); for(int i=0;i<t;i++) j[t].out(); return 0; }

This question is marked "community wiki".

asked 03 Jan, 09:44

greensand2's gravatar image

accept rate: 0%

wikified 03 Jan, 09:45

Your main function looks like:

int main()
   int t;
   cin >> t;

   job j[t];

   for (i=0; i<t; i++)

   for (i=0; i<t; i++)

   return 0;

Should be using j[i].

A debugger would probably have pointed to this. Could you learn to use gdb?


answered 04 Jan, 02:58

john_smith_3's gravatar image

accept rate: 26%

toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 03 Jan, 09:44

question was seen: 58 times

last updated: 04 Jan, 02:58