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.
AoC2022_Day13/main.cpp

56 lines
1.8 KiB

2 years ago
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include "olcutils.h"
#include "List.h"
2 years ago
using namespace olc;
int main()
{
std::ifstream file("input");
while (file.good()){
std::string line;
std::getline(file,line);
List*startingList=new List();
List*currentList=nullptr;
if (line.length()>0){
for (int i=0;i<line.length();i++){
if (line[i]=='['){
//std::cout<<"Read "<<line[i]<<"...";
if (currentList==nullptr){
currentList=startingList;
} else {
List*newList=new List();
Element el;
el.list=newList;
newList->parent=currentList;
currentList->elements.push_back(el);
currentList=el.list;
}
} else
if (line[i]==']'){
//std::cout<<"Read "<<line[i]<<"...";
currentList=currentList->parent;
} else
if (line[i]==','){
//std::cout<<"Read "<<line[i]<<"...";
continue;
} else {//Assume it's a digit.
std::string acc="";
while (line[i]>='0'&&line[i]<='9'){
//std::cout<<"Read "<<line[i]<<"...";
acc+=line[i++];
}
Element el;
el.number=std::atoi(acc.c_str());
currentList->elements.push_back(el);
i--;
}
}
std::cout<<line<<std::endl;
std::cout<<*startingList<<std::endl;
}
}
2 years ago
return 0;
}