Birthday Boy

Bobby has just joined a new company, and human resources has asked him to note his birthday on the office calendar. Bobby the Birthday Boy wants to feel special! Also, Bobby the Birthday Boy does not mind lying for attention.

He notices that the longer people have not celebrated a birthday or eaten cake, the more they like it when a new one comes around. So he wants to pick his birthday in such a way that the longest period of time without a birthday possible has just passed. Of course he does not want to share his birthday with any colleague, either.

Can you help him make up a fake birthday to make him feel as special as possible? Bobby does not care about leap years: you can assume every year is not a leap year, and that no one has a birthday on the 29th of February. In case of a tie, Bobby decides to fill in the date that is soonest (strictly) after the current date, the 27th of October, because that means he will get to celebrate his birthday as soon as possible.

Figure 1: Sample case 22. The calendar is from http://printablecalendarholidays.com.

Input

  • The first line has a number 1 \leq n \leq 1001≤n≤100, the number of colleagues Bobby has in his new office.

  • Then follow nn lines, each line corresponding to one coworker. Each line gives the name of the colleague (using at most 2020 upper- or lowercase letters a–z) separated from their birthday date by a space. The date is in format mm-dd.

Output

Print the fake birthday date (format: mm-dd) chosen by Bobby.

Sample 1

InputOutput
3
Henk 01-09
Roos 09-20
Pietje 11-11
09-19

Sample 2

InputOutput
16
Henk 01-09
Luc 12-31
Jan 03-22
Roos 09-20
Pietje 11-11
Anne 02-28
Pierre 09-25
Dan 12-15
Lieze 11-17
Charlotte 05-01
Lenny 08-02
Marc 04-25
Martha 06-12
John 03-26
Matthew 01-20
John 01-20
08-01

Sample 3

InputOutput
3
JohnIII 04-29
JohnVI 10-28
JohnIIX 04-28
04-27

Sample 4

InputOutput
3
CharlesII 04-30
CharlesV 10-29
CharlesVII 04-29
10-28

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
char s[100];
struct node
{
    int x, y, z;
};
int f1(int x)
{
    switch (x)
    {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        return 31;
    case 2:
        return 28;
    default:
        return 30;
    }
}
int f2(int x, int y)
{
    while (x--)
    {
        y += f1(x);
    }
    return y;
}
int f3(int x, int y) // 331代表10-28
{
    int i, j, k;
    if (f2(x, y) > 331)
        return (f2(x, y) - 331);
    else if (f2(x, y) < 331)
        return (f2(x, y) + 35);
    else //等于331要特判
        return 365;
}
bool cmp(node a, node b)
{
    return a.z < b.z;
}
node a[1100];
int main()
{

    int i, j, k, l, n;
    int max = -1, k1;
    int u, v;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%s%d-%d", s, &j, &k);
        a[i].z = f2(j, k);
        a[i].x = j;
        a[i].y = k;
    }
    sort(a, a + n, cmp);
    { //第一个数据的处理
        max = (a[0].z + (365 - a[n - 1].z));
        u = a[0].x;
        v = a[0].y;
    }
    for (i = 1; i < n; i++)
    {
        if ((a[i].z - a[i - 1].z) > max)
        {
            max = a[i].z - a[i - 1].z;
            u = a[i].x;
            v = a[i].y;
        }
        else if ((a[i].z - a[i - 1].z) == max)
        {
            if (f3(a[i].x, a[i].y) < f3(u, v))
            {
                u = a[i].x;
                v = a[i].y;
            }
        }
    }
    if (v == 1)
    {
        if (u == 1)
            printf("12-31\n");
        else
            printf("%02d-%02d\n", u - 1, f1(u - 1));
    }
    else
        printf("%02d-%02d\n", u, v - 1);
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值