Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大佬们帮看一下为什么wa啊(给一组hack就行#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<vector> #include<queue> #include<cmath> #include<map> #include<ctime> #define ll long long using namespace std; const int maxn=150; inline int rd() { int sum=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { sum=sum*10+ch-'0'; ch=getchar(); } return f*sum; } string s1,s2; int cnt; bool vis1[maxn],vis2[maxn]; struct edge { int id; char ch; } e; deque<edge>q1,q2; int main() { scanf("%s",&s1); s2=s1; if(s2.size()==0){printf("\n");return 0;} for(int i=0; i<s2.size(); i++) { if(s2[i]=='(') { e.id=i,e.ch=s2[i]; q1.push_back(e); } else if(s2[i]=='[') { e.id=i,e.ch=s2[i]; q2.push_back(e); } else if(s2[i]==')'&&q1.size()) { q1.pop_back(); vis1[i]=1; } else if(s2[i]==']'&&q2.size()) { q2.pop_back(); vis2[i]=1; } if(s2[i]==')'&&q1.size()==0&&vis1[i]==0) { s1.insert(i+cnt,"("); cnt++; } else if(s2[i]==']'&&q2.size()==0&&vis2[i]==0) { s1.insert(i+cnt,"["); cnt++; } } for(int i=0; i<q1.size(); i++) { s1.insert(q1[i].id+1+cnt,")"); // cout<<q1[i].id+1+cnt<<endl; cnt++; } for(int i=0; i<q2.size(); i++) { s1.insert(q2[i].id+1+cnt,"]"); cnt++; } cout<<s1<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator