File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < stack>
3+
4+ using namespace std ;
5+ const int maxn = 1000 ;
6+ int A[maxn];
7+ int B[maxn];
8+ bool IsPopOrder (const int *push, const int *pop, int length)
9+ {
10+ bool bPossible = false ;
11+ if (push != NULL && pop != NULL && length > 0 )
12+ {
13+ std::stack<int > stackData;
14+ int i = 0 ;
15+ int j = 0 ;
16+ while (j < length)
17+ {
18+ while (stackData.empty () || stackData.top () != pop[j])
19+ {
20+ if (i > length - 1 )
21+ break ;
22+ stackData.push (push[i]);
23+ ++i;
24+ }
25+ if (stackData.top () != pop[j])
26+ break ;
27+ stackData.pop ();
28+ ++j;
29+ }
30+ if (stackData.empty () && j == length)
31+ bPossible = true ;
32+ }
33+ return bPossible;
34+ }
35+
36+ int main ()
37+ {
38+ int count = 0 ;
39+ char c;
40+ while ((c = getchar ()) != ' \n ' )
41+ {
42+ if (c != ' ' )
43+ {
44+ A[count] = c - ' 0' ;
45+ count++;
46+ }
47+ }
48+ count = 0 ;
49+ while ((c = getchar ()) != ' \n ' )
50+ {
51+ if (c != ' ' )
52+ {
53+ B[count] = c - ' 0' ;
54+ count++;
55+ }
56+ }
57+ if (IsPopOrder (A, B, count + 1 ))
58+ cout << " True" ;
59+ else
60+ cout << " False" ;
61+ return 0 ;
62+ }
You can’t perform that action at this time.
0 commit comments