generated from sigonasr2/CPlusPlusProjectTemplate
Logic for testinput is good!
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
3f3d30dcc9
commit
0b1f29bfe9
Binary file not shown.
1
List.h
1
List.h
@ -5,5 +5,6 @@
|
||||
struct List{
|
||||
std::vector<Element>elements;
|
||||
List*parent;
|
||||
int index=0;
|
||||
friend std::ostream&operator<<(std::ostream&out,List&rhs);
|
||||
};
|
92
main.cpp
92
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].number<list1->elements[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<line.length();i++){
|
||||
if (line[i]=='['){
|
||||
//std::cout<<"Read "<<line[i]<<"...";
|
||||
@ -46,9 +109,24 @@ int main()
|
||||
i--;
|
||||
}
|
||||
}
|
||||
std::cout<<line<<std::endl;
|
||||
std::cout<<*startingList<<std::endl;
|
||||
if (j==0){
|
||||
list1=startingList;
|
||||
} else {
|
||||
list2=startingList;
|
||||
}
|
||||
}
|
||||
std::getline(file,line);
|
||||
std::cout<<"List 1: "<<*list1<<std::endl;
|
||||
std::cout<<"List 2: "<<*list2<<std::endl;
|
||||
int sum=0;
|
||||
bool passed=examineList(list1,list2);
|
||||
if (passed){
|
||||
sum+=index;
|
||||
std::cout<<"Passed! Sum:"<<sum<<std::endl;
|
||||
} else {
|
||||
std::cout<<"Failed"<<std::endl;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user