×

getting tle

 0 You can check you code manually: First, j=0; then in "while (j < n)", check some conditions: 1) j!=n-1, so if(j==n-1){ while(s.empty()==true){ if (s.top()==z){ s.pop(); } else{ flag=1; break; } } }  will not be run. 2) j=0, so a[j]=4 != z, which is equal 1, so if(a[j]==z){ cout<<"1"; z++; if(jz){ s.push(a[j]); j++; } else if(s.top()==z+1){ s.pop(); } }  from begin of code, you haven't push anything into stack, so stack will be empty, and as it is empty, it will never have anything called "top" as you write here: "s.top()==z+1", so after many conditions, variable j won't be changed, and j is still equal 0, of course, j
 0 Here is my code for that problem, which is Accepted :) My code is seem to be clear, and I hope that will help you :) http://ideone.com/7DNddh answered 27 Nov '14, 23:37 125●2●8 accept rate: 16%
 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:

×1,138
×729

question asked: 27 Nov '14, 22:04

question was seen: 899 times

last updated: 27 Nov '14, 23:37