60分求助

P1167 刷题

Hope888 @ 2022-09-03 14:30:31

#include<bits/stdc++.h>
using namespace std;
struct TIME
{
    int Year;
    int Mouth;
    int Day;
    int Hour;
    long long Minute;
};
class TOOL
{
    public:
        int JUDGE_LEAP_YEAR(int year)
        {
            if(year%4==0&&year%100!=0||year%400==0)return 1;
            return 0;
        }
        int DAYS_IN_A_MOUTH(int mouth,int year)
        {
            if(mouth==1||mouth==3||mouth==5||mouth==7||mouth==8||mouth==10||mouth==12)return 31;
            if(mouth==4||mouth==6||mouth==9||mouth==11)return 30;
            if(mouth==2)return 28+JUDGE_LEAP_YEAR(year);
        }
        int THE_UNIFIED_UNIT_IS_MINUTES(TIME time)
        {
            time.Minute+=time.Hour*60+time.Day*1440;
            for(int i=1;i<time.Mouth;i++)time.Minute+=DAYS_IN_A_MOUTH(i,time.Year)*1440;
            for(int i=0;i<time.Year;i++)time.Minute+=(356+JUDGE_LEAP_YEAR(i))*1440;
            return time.Minute;
        }
};
int CMP(int num1,int num2)
{
    return num2>num1;
}
int main()
{
    int n;
    cin>>n;
    TOOL tool;
    int Problem[5005]={0};
    for(int i=1;i<=n;i++)cin>>Problem[i];
    TIME Start,End;
    string str;
    cin>>str;
    int temp=0,numT=1;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]>='0'&&str[i]<='9')temp=temp*10+(str[i]-'0');
        else
        {
            switch(numT)
            {
                case 1:Start.Year=temp;
                case 2:Start.Mouth=temp;
                case 3:Start.Day=temp;
                case 4:Start.Hour=temp;
                case 5:Start.Minute=temp;
            }
            temp=0;
            numT++;
        }
    }
    Start.Minute=temp;
    temp=0;
    numT=1;
    cin>>str;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]>='0'&&str[i]<='9')temp=temp*10+(str[i]-'0');
        else
        {
            switch(numT)
            {
                case 1:End.Year=temp;break;
                case 2:End.Mouth=temp;break;
                case 3:End.Day=temp;break;
                case 4:End.Hour=temp;break;
                case 5:End.Minute=temp;break;
            }
            temp=0;
            numT++;
        }
    }
    End.Minute=temp;
    sort(Problem+1,Problem+1+n,CMP);
    int equal=tool.THE_UNIFIED_UNIT_IS_MINUTES(End)-tool.THE_UNIFIED_UNIT_IS_MINUTES(Start);
    int sum=0;
    while(equal>=Problem[sum+1])
    {
        if(sum>=n)break;
        equal-=Problem[sum+1];
        sum++;
    }
    cout<<sum;
    return 0;
}

|