1
0
Fork 0

Day 10 submission

This commit is contained in:
Marcus Penate 2021-12-10 00:31:06 -05:00
parent dfcc3b4f76
commit 27cedade38
2 changed files with 105 additions and 0 deletions

View File

@ -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;
}

View File

@ -0,0 +1,62 @@
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
string str_in;
string openers = "([{<";
string closers = ")]}>";
vector<unsigned long long> all_results;
while(cin >> str_in)
{
stack<char> parser;
unsigned long long result = 0;
bool bl_is_corrupted = false;
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])
{
bl_is_corrupted = true;
break;
}
else
{
parser.pop();
}
}
}
if (bl_is_corrupted)
{
continue;
}
while(!parser.empty())
{
result*=5;
result+=1+openers.find(parser.top());
parser.pop();
}
all_results.push_back(result);
}
sort(all_results.begin(),all_results.end());
cout << all_results[all_results.size()/2] << endl;
return 0;
}