1.栈的使用
2.一种做题方式,在草纸上人工做,想清楚先后顺序,然后让机器做
#include <stdio.h> #include <iostream> #include <stack> using namespace std; int num[1000]; int main() { int a, i, j; while(scanf("%d", &a) != EOF) { if ( a == 0 ) break; while(scanf("%d", &num[0])) { if(num[0] == 0) { cout << endl; break; } for(i = 1; i < a; i ++) cin >> num[i]; stack <int> st; int now = 0; int ok = 1; for ( i = 0; i < a; i++ ) { if ( now < num[i] ) { for ( j = now + 1; j <= num[i]; j++ ) st.push(j); st.pop(); now = num[i]; } else { if(st.top() != num[i]) { ok = 0; break; } else st.pop(); } } if ( ok == 0) cout << "No" << endl; else cout << "Yes" << endl; } } return 0; }