一、心得

 

二、题目及分析

 有(和),如果匹配输出1,如果不匹配输出0。

三、代码及结果

 

 1 #include <iostream>
 2 using namespace std;
 3 
 4 bool judge(char c[256]){
 5     int top=0;
 6     int i=0;
 7     while(c[i]!='@'){
 8         if(c[i]=='(') top++;
 9         if(c[i]==')'){
10             if(top>0) top--;
11             else return false;
12         }
13         i++;//忘记这一句 
14     }
15     if(top!=0) return false;
16     else return true;
17     
18 }
19 
20 int main(){
21     char c[256];
22     scanf("%s",c);
23     cout<<judge(c)<<endl;
24     return 0;
25 } 

栈2--括号的匹配

相关文章:

  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-21
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2021-09-28
  • 2021-06-27
  • 2021-11-21
相关资源
相似解决方案