Moderator: Board moderators
got AC .. code removed
2
[]
(([())])Is it necessary to create own class stack ?
int stk[1000], top = 0; // the stack
push an element x: stk[top++] = x;
popping an element: stk[--top]kbr_iut wrote:dont open a new thread as there is already many threads...think about that.
however ur program gives wrong output for this set of input.
input:
- Code: Select all
7
([])
(([()])))
([()[]()])()
([)]
(
()(
[()
ur output is:
- Code: Select all
Yes
No
Yes
Yes
No
No
No
My AC program gives:
- Code: Select all
Yes
No
Yes
No
No
No
No
Hope it will help.
Removed
#include<stdio.h>
#include<string.h>
char fb[200],tb[200];
int main()
{
char line[200]="";
int i,j,n,k,flag,l,p,q,an;
scanf("%d",&n);
for(int it=0;it<n;it++){
gets(line);
if(line[0]==NULL){printf("Yes\n");continue;}
k=0;l=0;flag=0;an=0;
for(i=0;line[i];i++){
if(line[i]==')' && fb[0]==NULL){flag=1;break;}
if(line[i]==']' && tb[0]==NULL){flag=1;break;}
if(line[i]=='(' && line[i+1]==']'){flag=1;break;}
if(line[i]=='[' && line[i+1]==')'){flag=1;break;}
if(line[i]=='('){
fb[k]='(';k++;
p=k;
}
if(line[i]=='['){
tb[l]='[';l++;
q=l;
}
if(line[i]==')'){
fb[p-1]=NULL;
p--;
k=p;
}
if(line[i]==']'){
tb[q-1]=NULL;
q--;
l=q;
}
}
if(flag==1){printf("No\n");}
else {
for(i=0;line[i];i++){
if(fb[i]==NULL && tb[i]==NULL)an=1;
else {
an=0;break;
}
}
if(an==1)printf("Yes\n");
else printf("No\n");
for(i=0;line[i];i++)line[i]=NULL;
}
}
return 0;
}
Users browsing this forum: No registered users and 1 guest