Pagini recente » Cod sursa (job #2909033) | Cod sursa (job #1638517) | Cod sursa (job #2405542) | Cod sursa (job #676626) | Cod sursa (job #2889697)
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
ifstream fin("paranteze.in");
ofstream fout("paranteze.out");
stack<char>s1;
stack<int>s2;
int n, nrmax;
char x;
int main()
{
fin>>n;
s1.push('0');
s2.push(0);
int i;
for(i=1; i<=n; i++)
{
fin>>x;
if(s1.top() == '(' && x ==')' || s1.top() == '[' && x ==']'||s1.top() == '{' && x =='}')
{
if(!s1.empty())
{
s1.pop();
s2.pop();
}
if(i -s2.top()> nrmax)
nrmax=i=s2.top();
}
else
{
s1.push(x);
s2.push(i);
}
}
fout<<nrmax;
fin.close();
fout.close();
return 0;
}