1354括弧匹配检验

题目链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1354

第一次代码如下

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char s[300];
 4 char sta[300];
 5 int pd(char s[300])
 6 {
 7     int top=0,i=0;
 8     while(i<=strlen(s))
 9     {
10         if(s[i]=='('||s[i]=='[')top++;
11         
12         if(s[i]==')'&&s[i-1]=='(')top--;
13         else top++;
14     
15         if(s[i]==']'&&s[i-1]=='[')top--;
16         else top++;
17         i++;
18     }
19     if(top!=0)return 0;
20     else return 1;    
21 }
22 int main()
23 {
24     gets(s);
25     if(pd(s))cout<<"OK";
26     else cout<<"Wrong";
27     return 0;
28 }

成绩如下

第二次代码如下:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char sta[300]={0};
 4 int main()
 5 {
 6     int t=0;
 7     string s;
 8     cin>>s;
 9     for(int i=0;i<=s.size()-1;i++)
10     {
11         if(s[i]=='('||s[i]=='[')sta[++t]=s[i];//如果是左括号就进栈 
12         if(s[i]==')'&&sta[t]=='(')t--;
13         else t++;
14         if(s[i]==']'&&sta[t]=='[')t--;
15         else t++;
16     }
17     if(t==0)cout<<"OK";
18     else cout<<"Wrong";
19     
20     return 0;
21 }

成绩如下(错误都和第一一样)

第三次代码如下:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char sta[300]={0};
 4 int main()
 5 {
 6     int t=0;
 7     string s;
 8     cin>>s;
 9     for(int i=0;i<=s.size()-1;i++)
10     {
11         if(s[i]=='('||s[i]=='[')sta[++t]=s[i];//如果是左括号就进栈 
12         
13         if(s[i]==')')if(sta[t]=='(')t--;
14         else t++;
15         
16         if(s[i]==']')if(sta[t]=='[')t--;
17         else t++;
18     }
19     if(t==0)cout<<"OK"<<endl;
20     else cout<<"Wrong"<<endl;
21     
22     return 0;
23 }

成绩如下:

第四次代码如下:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char sta[300]={0};
 4 int main()
 5 {
 6     int t=0;
 7     string s;
 8     cin>>s;
 9     for(int i=0;i<=s.size()-1;i++)
10     {
11         if(s[i]=='('||s[i]=='[')sta[++t]=s[i];//如果是左括号就进栈 
12         
13         if(s[i]==')'&&sta[t]=='(')t--;
14         
15         if(s[i]==']'&&sta[t]=='[')t--;
16 
17     }
18     if(t==0)cout<<"OK";
19     else cout<<"Wrong";
20     
21     return 0;
22 }

居然出现如此现象:

 

我晕。。。。怎么会出现83分。。。

转载于:https://www.cnblogs.com/tflsnoi/p/8259328.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值