Day 7 aoc in progress

This commit is contained in:
2022-12-13 17:40:47 +01:00
parent 2cbfc0ac0b
commit 5b0e6a6979
3 changed files with 1126 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
#include <bits/stdc++.h>
using namespace std;
struct File;
class Directory{
public:
Directory* parent;
string name;
vector<Directory*> subdirectories;
vector<File*> files;
long container_size;
Directory (Directory* parent, string name) : parent(parent), name(name){
subdirectories.clear();
files.clear();
container_size = 0;
}
};
struct File{
string name;
long size;
Directory* parent;
};
using ChangeDirectory = string;
using List = vector<string>;
using Command = variant<ChangeDirectory, List>;
int main(){
ifstream input_file("test.txt");
string line;
vector<Command> commands;
List current_list;
bool reading_list = false;
// Parsing the input so it is nicer to handle later on
while(getline(input_file, line)){
if(line[0] == '$'){
if(reading_list){
commands.push_back(current_list);
current_list.clear();
reading_list = false;
}
stringstream ss(line);
string _, comm;
ss >> _ >> comm;
if(comm == "cd"){
ChangeDirectory dir;
ss >> dir;
commands.push_back(dir);
} else{
reading_list = true;
}
} else{
current_list.push_back(line);
}
}
if(reading_list){
commands.push_back(current_list);
reading_list = false;
}
// Setting up initial, empty directory
Directory
// Mapping out the file directory from all the commands
for(auto c : commands){
if(c.index() == 0){
} else{
}
}
// Printing parsed commands
// for(auto c : commands){
// if(c.index() == 0){
// cout << "$ cd " << get<0>(c) << '\n';
// } else{
// cout << "$ ls\n";
// for(auto s : get<1>(c)){
// cout << s << '\n';
// }
// }
// }
return 0;
}