首页 > 代码库 > CF821C Okabe and Boxes

CF821C Okabe and Boxes

思路:

模拟。不一致的时候直接清空栈即可。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <vector>
 4 using namespace std;
 5 int main()
 6 {
 7     vector<int> v;
 8     int n, cnt = 1, ans = 0;
 9     string s;
10     cin >> n;
11     for (int i = 0; i < 2 * n; i++)
12     {
13         cin >> s;
14         if (s[0] == a)
15         {
16             int tmp;
17             scanf("%d", &tmp);
18             v.push_back(tmp);
19         }
20         else
21         {
22             if (!v.empty()) 
23             {
24                 if (v[v.size() - 1] == cnt) v.pop_back();
25                 else
26                 {
27                     v.clear();
28                     ans++;
29                 }
30             }
31             cnt++;
32         }
33     }
34     printf("%d\n", ans);
35     return 0;
36 }

 

CF821C Okabe and Boxes