#include <iostream>
#include <string>
using namespace std;

// ВАРИАНТ 13
// Описать структуру ZNAK, содержащую поля:
// фамилия, имя, знак зодиака,
// дата рождения (как массив из 3-х чисел)

struct ZNAK {
	string surname, name, zodiac;
	int birthday[3];
};

int main() {

	// ЧАСТЬ 1
	// Реализовать ввод данных с клавиатуры в массив, состоящий из 5 структур типа ZNAK.
	const int ZNAKS_LEN = 5;
	ZNAK* znaks[ZNAKS_LEN] = {};

	for (int i = 0; i < ZNAKS_LEN; i++) {
		cout << "=> ZNAK " << i << endl;
		ZNAK* person = new ZNAK();
		string date;

		while (person->name.empty()) {
			cout << "Enter name: ";
			getline(cin, person->name);
		}

		while (person->surname.empty()) {
			cout << "Enter surname: ";
			getline(cin, person->surname);
		}

		while (person->zodiac.empty()) {
			cout << "Enter zodiac sign: ";
			getline(cin, person->zodiac);
		}

		while (
			!person->birthday[0] ||
			!person->birthday[1] ||
			!person->birthday[2]
		) {
			cout << "Enter date of birth (dd.mm.yyyy): ";
			getline(cin, date);

			for (int j = 0; j < 3; j++) {
				string str_value = date.substr(0, date.find("."));
				date.erase(0, date.find(".") + 1);

				int value = atoi(str_value.c_str());
				if (!value) {
					person->birthday[j] = 0;
					break;
				}

				person->birthday[j] = value;
			}

			// Если день не подходит - повторяем цикл
			if (person->birthday[0] < 1 || person->birthday[0] > 31) {
				person->birthday[0] = 0;
				cout << "Wrong day!" << endl;
				continue;
			}

			// Если месяц не подходит - повторяем цикл
			if (person->birthday[1] < 1 || person->birthday[1] > 12) {
				person->birthday[1] = 0;
				cout << "Wrong month!" << endl;
				continue;
			}

			// Если год не подходит - повторяем цикл
			if (person->birthday[2] < 1900 || person->birthday[2] > 2009) {
				person->birthday[2] = 0;
				cout << "Wrong year!" << endl;
				continue;
			}
		}
		znaks[i] = person;
	}
	cout << "All catched up!" << endl << endl;

	// ЧАСТЬ 2
	// Вывести на экран информацию о людях, родившихся в тот год, значение которого введено с клавиатуры.
	int year_to_find = 0;
	while (!year_to_find) {
		string year_str;
		cout << "Enter year to find: ";
		getline(cin, year_str);

		year_to_find = atoi(year_str.c_str());
		if (year_to_find < 1900 || year_to_find > 2009) year_to_find = 0;
	}

	cout << endl << "Searching..." << endl;
	bool found = false;
	for (int i = 0; i < ZNAKS_LEN; i++) {
		if (znaks[i]->birthday[2] != year_to_find) continue;
		found = true;
		ZNAK* person = znaks[i];
		cout << "[";
		cout << person->birthday[0] << ".";
		cout << person->birthday[1] << ".";
		cout << person->birthday[2];
		cout << "] ";

		cout << person->name << " " << person->surname;
		cout << " - " << person->zodiac << endl;
	}

	// ЧАСТЬ 3
	// Если таких людей нет, то вывести соответствующее сообщение
	if (!found) cout << "No one found." << endl;
	

	return 0;
}