diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 8b88860..2b1c00a 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/List.h b/List.h index 4fcd1ec..e469332 100644 --- a/List.h +++ b/List.h @@ -5,5 +5,6 @@ struct List{ std::vectorelements; List*parent; + int index=0; friend std::ostream&operator<<(std::ostream&out,List&rhs); }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 64abf47..0c339f3 100644 --- a/main.cpp +++ b/main.cpp @@ -3,16 +3,79 @@ #include "olcutils.h" #include "List.h" +bool examineList(List*list1,List*list2){ + if (list1->index>=list1->elements.size()){ + return true; + } + while (true) { + if (list1->elements.size()>list2->elements.size()){ + return false; + } + if (list1->elements[list1->index].list!=nullptr){ + if (list2->elements[list2->index].list==nullptr){ + //List 1: List + //List 2: Number + List*prevPtr=list1; + while (list1->elements[list1->index].list!=nullptr){ + list1=list1->elements[list1->index].list; + } + //Now we should be at a number. + if (list1->elements[list1->index].number>list2->elements[list2->index].number){ + return false; + } + list1=prevPtr; + } else { + //List 1: List + //List 2: List + if (!examineList(list1->elements[list1->index].list,list2->elements[list2->index].list)){ + return false; + } + } + //It's a list. + } else { + //Compare number. + if (list2->elements[list2->index].list==nullptr){ + //List 1: Number + //List 2: Number + if (list1->elements[list1->index].number>list2->elements[list2->index].number){ + return false; + } + } else { + //List 1: Number + //List 2: List + List*prevPtr=list2; + while (list2->elements[list2->index].list!=nullptr){ + list2=list2->elements[list2->index].list; + } + //Now we should be at a number. + if (list2->elements[list2->index].numberelements[list1->index].number){ + return false; + } + list2=prevPtr; + } + } + list1->index++; + list2->index++; + if (list1->index>=list1->elements.size()||list2->index>=list2->elements.size()){ + break; + } + } + return true; +} + using namespace olc; int main() { - std::ifstream file("input"); + std::ifstream file("testinput"); + int index=1; while (file.good()){ std::string line; - std::getline(file,line); - List*startingList=new List(); - List*currentList=nullptr; - if (line.length()>0){ + List*list1; + List*list2; + for (int j=0;j<2;j++){ + std::getline(file,line); + List*startingList=new List(); + List*currentList=nullptr; for (int i=0;i