You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
2.2 KiB
119 lines
2.2 KiB
#include <iostream>
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include <set>
|
|
using namespace std;
|
|
|
|
int intoPriority(char ch)
|
|
{
|
|
int initalP = ch;
|
|
if (initalP < 97)
|
|
{
|
|
initalP -= 38;
|
|
} else {initalP -= 96;}
|
|
return initalP;
|
|
}
|
|
|
|
class CharCount
|
|
{
|
|
char key;
|
|
int count;
|
|
};
|
|
|
|
|
|
class CharCounter
|
|
{
|
|
vector<CharCount> cc;
|
|
|
|
public:
|
|
int insert(char ch)
|
|
{
|
|
// This is terrible, DO NOT COMMIT
|
|
for (int i {0}; i < 26; i++)
|
|
{
|
|
CharCount charCount = this.cc[i];
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
class RuckSack
|
|
{
|
|
public:
|
|
vector<char> aCompartment;
|
|
vector<char> bCompartment;
|
|
int priority;
|
|
|
|
RuckSack(string fullSack)
|
|
{
|
|
set<char> seen;
|
|
int half = fullSack.size()/2;
|
|
for (int i {0}; i<fullSack.size(); i++)
|
|
{
|
|
char currentChar = fullSack[i];
|
|
if (i < half)
|
|
{
|
|
aCompartment.push_back(currentChar);
|
|
seen.insert(currentChar);
|
|
cout << currentChar;
|
|
}
|
|
else
|
|
{
|
|
bCompartment.push_back(currentChar);
|
|
if (seen.find(currentChar) != seen.end())
|
|
priority = intoPriority(currentChar);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
string aString()
|
|
{
|
|
string s(this->aCompartment.begin(), this->aCompartment.end());
|
|
return s;
|
|
}
|
|
string bString()
|
|
{
|
|
string s(this->bCompartment.begin(), this->bCompartment.end());
|
|
return s;
|
|
}
|
|
};
|
|
|
|
int main()
|
|
{
|
|
string inputStr;
|
|
ifstream inputFile("input.txt");
|
|
vector<RuckSack> bags;
|
|
int totalPrioritySum {0};
|
|
int groupPrioritySum {0};
|
|
|
|
|
|
|
|
set<BTreeNode> groupBTree;
|
|
int i {0};
|
|
while (getline(inputFile, inputStr))
|
|
{
|
|
i++;
|
|
if (i % 3 == 0)
|
|
set<BTreeNode> groupBTree;
|
|
|
|
for (char c : inputStr)
|
|
{
|
|
|
|
}
|
|
RuckSack curRuckSack {RuckSack(inputStr)};
|
|
cout << curRuckSack.aString() << "\t\t\t" << curRuckSack.bString() << endl;
|
|
|
|
totalPrioritySum += curRuckSack.priority;
|
|
bags.push_back(curRuckSack);
|
|
}
|
|
|
|
for (RuckSack rs: bags)
|
|
{
|
|
cout << rs.priority << endl;
|
|
}
|
|
cout << totalPrioritySum << endl;
|
|
|
|
|
|
} |