What should be the potential reason to get runtime error for this program?
Posted
by
MiNdFrEaK
on Stack Overflow
See other posts from Stack Overflow
or by MiNdFrEaK
Published on 2012-12-09T14:41:40Z
Indexed on
2012/12/09
17:04 UTC
Read the original article
Hit count: 222
#include<iostream>
#include<stack>
#include<vector>
#include<string>
#include<fstream>
#include<cstdlib>
/*farnaws,C++,673,08/12/2012*/
using namespace std;
string verifier(string input_line)
{
stack <char> braces;
for(int i=0; i<input_line.size(); i++)
{
if(input_line[i]=='(' || input_line[i]=='[')
{
braces.push(input_line[i]);
}
else if(input_line[i]==')' || input_line[i]==']')
{
braces.pop();
}
}
if(braces.size()==0)
{
return "YES";
}
else
{
return "NO";
}
}
int main()
{
ifstream file_input("input.in");
string read_file;
vector<string> file_contents;
if(file_input.is_open())
{
while(file_input>>read_file)
{
file_contents.push_back(read_file);
}
}
else
{
cout<<"File cant be open!"<<endl;
}
int limit=atoi(file_contents[0].c_str());
//cout<< limit;
ofstream file_output("output.out");
if(file_output.is_open())
{
for(int i=1; i<=limit; i++ )
{
file_output<<verifier(file_contents[i])<<endl;
}
}
else
{
cout<<"File cant be open!"<<endl;
}
return 0;
}
© Stack Overflow or respective owner