1
0
Fork 0
Advent2021/Day 10/Marcus/cpp/part1.cpp

43 lines
931 B
C++
Raw Normal View History

2021-12-10 05:31:06 +00:00
#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;
}