×

# Why doesn't the following code for CLEANUP work?

 0 #include #include #include using namespace std; int main() { int t; cin >> t; while(t--) { int num_job, job_com; cin >> num_job >> job_com; vector j; int k; for(int i = 0; i < job_com; i++) { cin >> k; j.push_back(k); } if(num_job == job_com) { cout << endl; cout << endl; } else { sort(j.begin(), j.end()); bool m = true; vector chef; vector ass; int l = 1; int i = 1; while(l<=num_job - job_com) { while(m == true && l <= num_job - job_com) { if(i == j[0]) { i = i + 1; j.erase(j.begin()); } else if(i != j[0]) { chef.push_back(i); i = i + 1; m = false; l = l + 1; } } while(m == false && l <= num_job - job_com) { if(i == j[0]) { i = i + 1; j.erase(j.begin()); } else if(i != j[0]) { ass.push_back(i); i = i + 1; m = true; l = l + 1; } } } int yo = chef.size(); int oy = ass.size(); for(int c = 0; c < yo; c ++) { cout << chef[c] << " "; } cout << endl; if(oy != 0) { for(int c = 0; c < oy; c ++) { cout << ass[c] << " "; } cout << endl; } else { cout << endl; } } } return 0; } It works fine on my machine, but when I submit it, I get an SIGSEGV error. asked 02 Oct '16, 21:12 2★ritik 11●1 accept rate: 0%

 0 Hi This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an vector element out of bounds, or using too much memory. Some things for you to try: Make sure you aren't using variables that haven't been initialized. These may be set to 0 on your computer, but aren't guaranteed to be on the judge. Check every single occurrence of accessing an vector element and see if it could possibly be out of bounds. Hope this helps. answered 02 Oct '16, 22:05 3★smsubham 675●2●16 accept rate: 15%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×316
×29

question asked: 02 Oct '16, 21:12

question was seen: 402 times

last updated: 02 Oct '16, 22:12