特定字符序列的判断
1 #include <iostream>
2 #include <cstdlib>
3 #include <stack>
4 #include <string>
5 using namespace std;
6
7 int main()
8 {
9 stack<char> s;
10 stack<char> s1;
11 char c, c1;
12 string str;
13 cin>>str;
14 int i=0;
15 while(1)
16 {
17 c = str[i];
18 if (c == '#')
19 {
20 break;
21 }
22 s.push(c);
23 i++;
24 }
25
26 while(1)
27 {
28 c1 = s.top();
29 s.pop();
30 if (c1 == '@')
31 {
32 break;
33 }
34 s1.push(c1);
35 }
36
37 if (s.size()!=s1.size())
38 {
39 cout<<"no!";
40 return 0;
41 }
42
43 while(!s.empty())
44 {
45 if(s.top()!=s1.top())
46 {
47 cout<<"no!";
48 return 0;
49 }
50 s.pop();
51 s1.pop();
52 }
53
54 cout<<"yes!";
55
56 return 0;
57 }