#include<stdio.h>
#include<string.h>
int top,flag,i;
char br[130],stck[130];
void push(void);
void pop(void);
int main()
{
int t,len;
scanf("%d ",&t);
while(t--)
{
gets(br);
top=flag=0;
len=strlen(br);
for(i=0; i<len; i++)
{
if(br[i]=='('||br[i]=='[')
push();
else
pop();
if(flag==1)
break;
}
if(top>0)
flag=1;
if(flag==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
void push(void)
{
stck[top++]=br[i];
return;
}
void pop(void)
{
if (top==0)
{
flag=1;
return;
}
else if((br[i]==')'&&stck[--top]!='(') || (br[i]==']'&&stck[--top]!='['))
flag=1;
return;
}
এতে সদস্যতা:
মন্তব্যগুলি পোস্ট করুন
(
Atom
)
ভাই,আমার এই কোডে রানটাইম ইরোর দেখাচ্ছে কেনো??
উত্তরমুছুন#include
#include
#include
using namespace std;
struct stak
{
char data;
struct stak *next;
};
void parenthesis(char *ch)
{
struct stak *temp=NULL,*head=NULL;
int p=0;
for(int i=0; *(ch+i); i++)
{
if(*(ch+i)=='(' || *(ch+i)=='[')
{
temp=(struct stak*)malloc(sizeof(struct stak));
temp->data=*(ch+i);
temp->next=head;
head=temp;
p=1;
}
else if(*(ch+i)==')' || *(ch+i)==']')
{
if(head==NULL)
break;
else if(head->data=='(' && *(ch+i)==')')
{
head=head->next;
delete(temp);
}
else if(head->data=='[' && *(ch+i)==']')
{
head=head->next;
delete(temp);
}
else
break;
}
}
if(head==NULL && p==1)
cout<<"Yes\n";
else
cout<<"No\n";
}
int main()
{
int n;
cin>>n;
string str;
while(n--)
{
getline(cin,str);
if(str=="")
cout<<"Yes\n";
else
parenthesis(&str[0]);
}
return 0;
}