#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int comp(pair<int,double> l, pair<int,double> r)
{
return l.second > r.second;
}
struct Date
{
int day;
int month;
int year;
double conf;
};
int cmpDate(Date l, Date r)
{
return l.conf > r.conf;
}
// corrects the year
vector<pair<int,double>> year(vector<vector<pair<int,double>> > source, int k)
{
int count = 0;
vector<pair<int,double> > firstBox;
vector<pair<int,double> > secondBox;
vector<pair<int,double> > thirdBox = source[6];
vector<pair<int,double> > fourthBox = source[7];
firstBox.push_back(source[4][1]);
firstBox.push_back(source[4][2]);
secondBox.push_back(source[5][0]);
secondBox.push_back(source[5][9]);
secondBox.push_back(source[5][1]);
vector<pair<int,double>> yearsRes;
int y = 0;
double conf = 1.0;
// overrunning each box using
for(int i = 0; i < firstBox.size(); ++i)
{
for(int j = 0; j < secondBox.size(); ++j)
{
for(int m = 0; m < 10; ++m)
{
for(int n = 0; n < 10; ++n)
{
y=firstBox[i].first*1000 + secondBox[j].first*100 +thirdBox[m].first*10 +fourthBox[n].first;
conf=firstBox[i].second*secondBox[j].second*thirdBox[m].second*fourthBox[n].second;
// Checking if this number enters the range
if(y >= 1900 && y <= 2199)
yearsRes.push_back(pair<int,double>(y,conf));
}
}
}
}
// sorting the result array and select k years with the biggest probability
sort(yearsRes.begin(), yearsRes.end(),comp);
return vector<pair<int,double> > (yearsRes.begin(), yearsRes.begin() + k);
}
// Correcting the month
vector<pair<int,double>> month(vector<vector<pair<int,double>> > source, int n)
{
pair<int,double> boxOne = source[2][1];
pair<int,double> boxZero = source[2][0];
int number;
double conf;
vector<pair<int,double>> res;
// overrunning month from 10 to 12
for(int i =0; i < 3;++i)
{
number = boxOne.first*10 + source[3][i].first;
conf = boxOne.second*source[3][i].second;
res.push_back(pair<int,double>(number,conf));
}
// overrunning month from 01 to 09
for(int i = 1; i < 10; ++i)
{
number = boxZero.first*10 + source[3][i].first;
conf = boxZero.second*source[3][i].second;
res.push_back(pair<int,double>(number,conf));
}
// sort
sort(res.begin(), res.end(), comp);
return vector<pair<int,double> > (res.begin(), res.begin() + n);
}
// Corrects the day
vector<pair<int,double> > day(vector<vector<pair<int,double>> > source, int m)
{
int number;
double conf;
vector<pair<int,double> > res;
// overrunning month from 01 to 09
for(int i = 1; i < 10; ++i)
{
number = source[0][0].first*10 + source[1][i].first;
conf = source[0][0].second*source[1][i].second;
res.push_back(pair<int,double>(number,conf));
}
// overrunning month from 10 to 19
for(int i = 0; i < 10; ++i)
{
number = source[0][1].first*10 + source[1][i].first;
conf = source[0][1].second*source[1][i].second;
res.push_back(pair<int,double>(number,conf));
}
// overrunning month from 20 to 29
for(int i = 0; i < 10; ++i)
{
number = source[0][2].first*10 + source[1][i].first;
conf = source[0][2].second*source[1][i].second;
res.push_back(pair<int,double>(number,conf));
}
// overrunning month from 30 to 31
for(int i = 0; i < 2; ++i)
{
number = source[0][3].first*10 + source[1][i].first;
conf = source[0][3].second*source[1][i].second;
res.push_back(pair<int,double>(number,conf));
}
sort(res.begin(), res.end(),comp);
return vector<pair<int,double>> (res.begin(), res.begin() + m);
}
// forms the dateString
string formDate(Date d)
{
string date = "";
if(d.day < 10)
{
date+='0';
date+= d.day +'0';
date+='.';
}
else
{
date+= d.day/10 + '0';
date+= d.day%10 + '0';
date+= ".";
}
if(d.month < 10)
{
date+='0';
date+= d.month + '0';
date+='.';
}
else
{
date+= d.month/10 + '0';
date+= d.month%10 + '0';
date+= ".";
}
date+=d.year/1000 + '0';
d.year%=1000;
date+=d.year/100 + '0';
d.year%=100;
date+=d.year/10 + '0';
date+=d.year%10 + '0';
return date;
}
// returns corrected date
string date_result(vector<vector<pair<int,double>> > source, int m, int n, int k)
{
string date = "";
vector<pair<int,double>> y = year(source,k);
vector<pair<int,double>> mm = month(source, n);
vector<pair<int,double>> d = day(source, m);
vector<Date> res;
int tempYear;
int tempMonth;
int tempDay;
double conf;
// overruns each tripples and forms the array of combinations
for(int yCount = 0; yCount < k;++yCount)
{
for(int mCount = 0; mCount <n; ++mCount)
{
for(int dCount = 0; dCount < m; ++dCount)
{
tempYear = y[yCount].first;
tempMonth = mm[mCount].first;
tempDay = d[dCount].first;
conf = y[yCount].second*mm[mCount].second*d[dCount].second;
Date date;
date.day = tempDay;
date.month = tempMonth;
date.year = tempYear;
date.conf = conf;
res.push_back(date);
}
}
}
sort(res.begin(), res.end(), cmpDate);
int daySample[] = {31,28,31,30,31,30,31,31,30,31,30,31};
//overruns the array of combinations and checks if the date is valid. If it is valid, sends it to formData() function
for(int i = 0; i < res.size(); ++i)
{
bool checkYear = (res[i].year%4 == 0 && res[i].year%100 != 0) || (res[i].year%400 == 0);
if(res[i].month == 2)
{
if(checkYear && res[i].day >= 1 && res[i].day <= 29)
{
date = formDate(res[i]);
break;
}
else if(!checkYear && res[i].day >= 1 && res[i].day <= 28)
{
date = formDate(res[i]);
break;
}
}
else if(res[i].day >= 1 && res[i].day <= daySample[res[i].month-1])
{
date = formDate(res[i]);
break;
}
}
return date;
}
int main()
{
vector<vector<pair<int,double> > > source(8);
int length = 8, num = 10;
vector<pair<int,double>> temp(num);
double ver;
for(int i = 0; i < length; ++i)
{
for(int j = 0; j < num; ++j)
{
cin >> ver;
temp[j] = pair<int,double> (j, ver);
}
source[i] = temp;
}
int n = 2, m = 3, k = 3;
cout << date_result(source,n,m,k) << endl;
}