习题3.9 堆栈操作合法性

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n,c = 0,m;
 8     cin>>n>>m;
 9     string s;
10     while(n--)
11     {
12         cin>>s;
13         c = 0;
14         for(int i = 0; i < s.size(); i ++)
15         {
16             if(s[i] == 'S')
17             {
18                 c ++;
19                 if(c > m)
20                     break;
21             }
22             else
23             {
24                 c --;
25                 if(c < 0)
26                     break;
27             }
28         }
29         if(c == 0)
30             cout<<"YES"<<endl;
31         else
32             cout<<"NO"<<endl;
33     }
34 }

猜你喜欢

转载自www.cnblogs.com/FengZeng666/p/9720809.html
3.9