pipioj 1209: 模拟出入栈游戏(简单模拟)

http://www.pipioj.online/problem.php?id=1209

 1 #define IO std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 2 #define bug(x) cout<<#x<<" is "<<x<<endl
 3 #include <bits/stdc++.h>
 4 #define iter ::iterator
 5 using namespace  std;
 6 typedef long long ll;
 7 typedef pair<int,ll>P;
 8 #define pb push_back
 9 #define mk make_pair
10 #define se second
11 #define fi first
12 #define rs o*2+1
13 #define ls o*2
14 const ll mod=1e9+7;
15 const int N=1e2+5;
16 int T;
17 char s[N],t[N];
18 int vis[N];
19 int main(){
20     //IO;
21     while(~scanf("%s",s+1)){
22         int cnt=0,r=0,f=0;
23         for(int i=0;i<=26;i++)vis[i]=0;
24         for(int i=1;i<=26;i++){
25             int x=s[i]-'a';
26             vis[x]++;
27             if(vis[x]>1){
28                 f=1;
29                 break;
30             }
31             if(cnt>1&&x<t[cnt]){
32                 f=1;
33                 break;
34             }
35             if(cnt>0&&t[cnt]==x)cnt--;
36             for(int p=r;p<x;p++)t[++cnt]=p;
37             r=max(r,x+1);
38         }
39         if(cnt>0)f=1;
40         if(f)puts("no");
41         else puts("yes");
42     }
43 }
原文地址:https://www.cnblogs.com/ccsu-kid/p/14509264.html