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

 
 
 
日一二三四五六
       
       
       
       
       
       

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

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

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月22日漏签0天
数据结构吧 关注:104,520贴子:883,654
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 1回复贴,共1页
<<返回数据结构吧
>0< 加载中...

求助求助求助

  • 只看楼主
  • 收藏

  • 回复
  • “123”__
  • 单链表
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define max_size 100000
class stack{
public:
int top;
char data[max_size];
int index[max_size];
stack(){
top = 0;
}
void Pushstack(char v,int pos){
if(top<max_size){
data[top]=v;
index[top]=pos;
top++;
}
}
bool Popstack(char& v,int& pos){
if(top==0) return false;
top--;
v=data[top];
pos=index[top];
return true;
}
bool isempty(){
return top==0;
}
};
int main(){
string s;
while(getline(cin,s)){
stack S;
int cnt = 0;
bool ifmatch[max_size] = {false};
for(int i=0;s.size();i++){
char c = s[i];
if(c=='('||c=='{'||c=='['){
S.Pushstack(c,i);
}else if(c==')'||c==']'||c=='}'){
char x;
int n;
if(S.Popstack(x,n)){
bool m = false;
if(x=='('&&c==')'){
cnt++;
m = true;
}else if(x=='['&&c==']'){
cnt++;
m = true;
}else if(x=='{'&&c=='}'){
cnt++;
m = true;
}
if(m){
ifmatch[i] = true;
ifmatch[n] = true;
}else{
ifmatch[i] = false;
}
}else{
ifmatch[i] = false;
}
}
}
while(!S.isempty()){
char x;
int n;
S.Popstack(x,n);
ifmatch[n] = false;
}
cout<<cnt<<endl;
bool unmatch = false;
for(int i=0;s.size();i++){
if(!ifmatch[i]){
cout<<s[i];
unmatch = true;
}
}
if(!unmatch){
cout<<" ";
}
cout<<endl;
}
return 0;
}
学校平台一直显示运行错误63%,有大佬帮忙看看指出问题吗。


  • 曹编程之德彪踏马
  • 二叉树
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
可以调试


登录百度账号

扫二维码下载贴吧客户端

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