#12529: C++ 簡易參考解答


shawn2000100 (東華財金)

學校 : 國立東華大學
編號 : 57300
來源 : [27.53.168.5]
最後登入時間 :
2021-09-19 19:53:19
c123. 00514 - Rails -- UVa514 | From: [124.9.163.172] | 發表日期 : 2017-08-07 21:43

#include <iostream>
#include <vector>
using namespace std;

int main() {
int B[1001], N, cnt;

while ( cin >> N && N ) {
while ( cin >> B[0] && B[0] ) {
for ( int i = 1; i < N; ++i )
cin >> B[i];

cnt = 0;
vector <int> station;

for ( int i = 1; i <= N; ++i ) {
station.push_back(i);

while ( station.back() == B[cnt] && !station.empty() ) {
++cnt;
station.pop_back();
}
}

cout << ( ( station.empty() ) ? "Yes" : "No" ) << endl;
}
}

return 0;
}

 
ZeroJudge Forum