Pagini recente » Cod sursa (job #1879320) | Cod sursa (job #1305752) | Cod sursa (job #563419) | Cod sursa (job #1098362) | Cod sursa (job #2043504)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("parantezare.in");
ofstream g("parantezare.out");
char st[100001][2];
int top;
struct nod
{
int prima, ultima;
nod *next;
};
nod*p;
void push (char x, int i)
{
if(top<100001)
st[++top][0]=x, st[top][1]='0'+i;
}
void pop(int i)
{int j;
if(top>0)
{top--;
j=int(st[top+1][1]-'0');
nod *c;
c=new(nod);
c->prima=j;
c->ultima=i;
c->next=p;
if(p==NULL)
{
p=c;
p->next=NULL;
}
else
p=c;
}
}
int paranteza (char s[100001])
{
unsigned int i, n=strlen(s);
for(i=0;i<n;++i)
if(s[i]=='('|| s[i]==')')
{
if(top==0)
{
if(s[i]=='(')
push(s[i], i);
}
else
if(s[i]=='(')
push(s[i], i);
else
pop(i);
}
if(top) return 0;
return 1;
}
void caut (int x)
{
nod *c;
c=new(nod);
c=p;
while(c && c->prima!=x)
c=c->next;
g<<c->ultima<<" ";
}
void citire()
{ int x, M;
char s[100001];
f>>s;
if(paranteza(s))
{
f>>M;
while(M--)
{
f>>x;
caut(x);
}
}
else
g<<"sirul nu este parantezat corect";
f.close();
g.close();
}
int main()
{
citire();
}