13862 - Pineapple senpai’s family

                Never    
C++
       
#include <iostream>
#include<string>
#include "function.h"

    void Person::describe(string* arr, int now, int len) {
    if (len == 2) {
        string attribute = arr[now];
        string value = arr[now + 1];
        if (attribute == "Gender") {
            this->gender = (value == "MALE") ? MALE : FEMALE;
        } else if (attribute == "Age") {
            this->age = stoi(value);
        } else if (attribute == "Name") {
            this->name = value;
        } else if (attribute == "Personality") {
            this->personality += " " + value;
        }
    } else if (len > 2) {
        string relation = arr[now];
        Person* nextRelative = nullptr;
        if (relation == "ParentA" && this->parentA != nullptr) {
            nextRelative = this->parentA;
        } else if (relation == "ParentB" && this->parentB != nullptr) {
            nextRelative = this->parentB;
        } else if (relation == "Mate" && this->mate != nullptr) {
            nextRelative = this->mate;
        } else if (relation == "Child" && this->child != nullptr) {
            nextRelative = this->child;
        } else {
            if (relation == "ParentA") {
                this->parentA = new Person();
                if(this->parentB != nullptr){
                    this->parentA->mate = this->parentB;
                }
                this->parentA->child = this;
                nextRelative = this->parentA;
            } else if (relation == "ParentB") {
                this->parentB = new Person();
                if(this->parentA != nullptr){
                    this->parentB->mate = this->parentA;
                }
                this->parentB->child = this;
                nextRelative = this->parentB;
            } else if (relation == "Mate") {
                this->mate = new Person();
                this->mate->mate = this;
                if (this->child != nullptr) {
                    this->child->parentB = this->mate;
                    this->mate->child = this->child;
                }
                nextRelative = this->mate;
            } else if (relation == "Child") {
                this->child = new Person();
                this->child->parentA = this;
                if(this->mate != nullptr){
                    this->child->parentB = this->mate;
                }
                nextRelative = this->child;
            }
        }
        if (nextRelative != nullptr) {
            nextRelative->describe(arr, now + 1, len - 1);
        }
    }
}
    Person* Person::getRelative (string* arr, int now, int len){
            if(now == len) return this;
            string relation = arr[now];
            if (relation == "ParentA") {
            if (this->parentA == nullptr) {
                this->parentA = new Person();
                if(this->parentB != nullptr){
                    this->parentA->mate = this->parentB;
                }
                this->parentA->child = this;
            }
            return this->parentA->getRelative(arr, now + 1, len);
            }
            else if (relation == "ParentB") {
                if (this->parentB == nullptr) {
                    this->parentB = new Person();
                    if(this->parentA != nullptr){
                        this->parentB->mate = this->parentA;
                    }
                    this->parentB->child = this;
                }
                return this->parentB->getRelative(arr, now + 1, len);
            }
            else if (relation == "Mate") {
                if (this->mate == nullptr) {
                    this->mate = new Person();
                    this->mate->mate = this;
                    if (this->child != nullptr) {
                        this->child->parentB = this->mate;
                        this->mate->child = this->child;
                    }
                }
                return this->mate->getRelative(arr, now + 1, len);
            }
            else if (relation == "Child") {
                if (this->child == nullptr) {
                    this->child = new Person();
                    this->child->parentA = this;
                    if(this->mate != nullptr){
                        this->child->parentB = this->mate;
                    }
                }
            return this->child->getRelative(arr, now + 1, len);
            }
            return this;
    }

Raw Text