UVa 514: Rails
2017-01-08 14:58
330 查看
怎么进来就想想它怎么回去。
#include <iostream> #include <stack> using namespace std; int main() { stack<int> in_station; int num_carriage; while(cin >> num_carriage && num_carriage != 0) { if(num_carriage < 1 || num_carriage > 1000) continue; int *seq_carriage = new int[num_carriage]; while(cin >> seq_carriage[0] && seq_carriage[0] != 0) { // in_station.push(seq_carriage[0]); int seq_top = num_carriage + 1; for(int i = 1; i < num_carriage; i++) { cin >> seq_carriage[i]; } int result = 0; for(int i = num_carriage - 1; i >= 0; i--) { int top_stack; result = 0; // push to the temporary station if(!in_station.empty()) { top_stack = in_station.top(); result = 1; } if (result && top_stack > seq_carriage[i]) { break; } in_station.push(seq_carriage[i]); top_stack = in_station.top(); // pop the train. while(seq_top == top_stack + 1 ) { in_station.pop(); seq_top = top_stack; if (in_station.empty()) { break; } top_stack = in_station.top(); } } if(!in_station.empty()) cout << "No" << endl; else cout << "Yes" << endl; while(!in_station.empty()) { in_station.pop(); } } cout << endl; delete []seq_carriage; } return 0; }
相关文章推荐
- uva 514 Rails
- 【STL】uva 514 Rails
- UVA 514 rails
- Uva 514 Rails
- uva514 Rails 栈相关问题
- UVA 514 Rails(栈)
- UVa 514 Rails
- UVA 514 - Rails && POJ 1363 (堆栈模拟)
- UVa 514 Rails
- UVa 514 Rails(铁轨) 栈
- UVa 514 (stack的使用) Rails
- Uva 514 Rails
- UVa 514 - Rails
- UVA 514 - Rails(模拟)
- UVa 514 - Rails【栈+格式】
- UVA 514 - Rails
- UVa 514 Rails(模拟栈)
- Uva - 514 - Rails
- UVa - 514 Rails(栈模拟)
- UVa 514 - Rails