网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
09月03日漏签0天
c++吧 关注:631,487贴子:2,114,012
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 8回复贴,共1页
<<返回c++吧
>0< 加载中...

【求助】关于栈的。。

  • 只看楼主
  • 收藏

  • 回复
  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
2楼贴题


  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Parentheses Balance
You are given a string consisting of parentheses () and []. A string of this type is said to be correct:
(a)
if it is the empty string (b)
if A and B are correct, AB is correct, (c)
if A is correct, (A) and [A] is correct. Write a program that takes a sequence of strings of this type and check their correctness. Your program can assume that the maximum string length is 128. Input The file contains a positive integer n and a sequence of n strings of parentheses () and [], one string a line. Output A sequence of Yes or No on the output file. Sample Input 3 ([]) (([()]))) ([()[]()])() Sample Output Yes No Yes


2025-09-03 19:09:47
广告
不感兴趣
开通SVIP免广告
  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
You are given a string consisting of parentheses () and []. A string of this type is said to be correct:
(a) if it is the empty string
(b) if A and B are correct, AB is correct,
(c) if A is correct, (A) and [A] is correct.
Write a program that takes a sequence of strings of this type and check their correctness. Your program can assume that the maximum string length is 128.
Input
The file contains a positive integer n and a sequence of n strings of parentheses () and [], one string a line.
Output
A sequence of Yes or No on the output file.
Sample Input
3
([])
(([()])))
([()[]()])()
Sample Output
Yes
No
Yes 


  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
下面是我的代码。帮忙看一下哪里有问题
#include<stdio.h>
#include<iostream>
#include<stack>
#include<string.h>
using namespace std;
int main()
{
char str[200];
int mark,n,len,i;
scanf("%d",&n);
cin.get();
while (n--)
{
stack <int> s;
gets(str);
len=strlen(str);
s.push(1);
for(i=0; i<len; i++)
{
if(str[i]=='('||str[i]=='[')
s.push(str[i]);
if(str[i]==')')
{
if(s.top()=='(')
{
s.pop();
continue;
}
else
{
printf("no\n");
break;
}
}
else if(str[i]==']')
{
if(s.top()=='[')
{
s.pop();
continue;
}
else
{
printf("no\n");
break;
}
}
}
if(i==len)
{
s.pop();
if(s.empty()) printf("yes\n");
else printf("no\n");
}
}
return 0;
}


  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
来人额


  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

@飞翔的天地
@ 关签
@ 御坂美琴みさか
来人额。。


  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

@飞翔的天地
@关签
@御坂美琴みさか 


  • 『木辛子』
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
???


2025-09-03 19:03:47
广告
不感兴趣
开通SVIP免广告
  • tcet030840zxp
  • &
    9
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
楼主程序没错,但犯个弱智错误,检查输出和题目要求的一样不?注意大小写


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 8回复贴,共1页
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示