Day 10 submission
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string str_in;
|
||||
string openers = "([{<";
|
||||
string closers = ")]}>";
|
||||
int result = 0;
|
||||
int scores[4] = {3,57,1197,25137};
|
||||
|
||||
while(cin >> str_in)
|
||||
{
|
||||
stack<char> parser;
|
||||
|
||||
for(unsigned int i = 0; i < str_in.size(); i++)
|
||||
{
|
||||
size_t found_pos;
|
||||
if (openers.find(str_in[i])!=string::npos)
|
||||
{
|
||||
parser.push(str_in[i]);
|
||||
}
|
||||
else if ((found_pos=closers.find(str_in[i]))!=string::npos)
|
||||
{
|
||||
if (parser.top() != openers[found_pos])
|
||||
{
|
||||
result += scores[found_pos];
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << result << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user