UVA 12541-Birthdates Solutions

Took hints from here:
http://www.outsbook.com/uva/?page=latest_post&category=-1&id=12541
and https://github.com/morris821028/UVa/blob/master/volume125/12541%20-%20Birthdates.cpp
Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    int n,i;
    while(scanf("%d",&n)==1)
    {
        int x,dd,mm,yyyy,minimum_age_old=0,maximum_age_young=22222222;
        string oldage,youngage,name;
        for(i=0; i<n; i++)
        {
            cin>>name>>dd>>mm>>yyyy;
            x=yyyy*10000+mm*100+dd; //converting it to integer
            if(x>minimum_age_old)  //here comparison is going on with previous value that saved in memory
            {
                minimum_age_old=x;
                oldage=name;
            }
            if(x<maximum_age_young) //here is also comparison going on with the previous value that saved in the variable memory
            {
                maximum_age_young=x;
                youngage=name;
            }
        }
        cout<<oldage<<endl; //younger print
        cout<<youngage<<endl; //older print

    }
    return 0;
}

Some links for future use:
http://reza22cse.blogspot.com/2014/01/uva-12541-birthdates.html
https://github.com/dibery/UVa/blob/master/contest/vol125/12541.cpp
https://gist.github.com/I-See-You/e8066e0b3a2ffbf5430e
http://ajmarin.alwaysdata.net/codes/problems/1501/

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *