为什么WAandRE

P1167 刷题

S0CRiA @ 2020-11-04 21:18:12

//P1167
#include <algorithm>
#include <iostream>
using namespace std;
int a[5005];

bool leap_year(int n){
    if(n%4==0 &&(n%100!=0 || n%400==0)) return true;
    return false;
}

int days_of_a_month(int i,int j){
    if(j==1 || j==3 || j==5 || j==7 || j==8 || j==10 || j==12)return 31;
    else if(j==4 || j==6 || j==9 || j==11)                    return 30;
    else if(leap_year(i))                                     return 29;
    else                                                      return 28;
}

int sjc(int y1,int m1,int d1,int y2,int m2,int d2){
    int year=0,month=0,day=0;
    for(int i=999; i<y2; i++){year+=365;if(leap_year(i)) year++;}
    for(int i=999; i<y1; i++){year-=365;if(leap_year(i)) year--;}
    for(int i=1; i<m2; i++)  {month+=days_of_a_month(y2,i);}
    for(int i=1; i<m1; i++)  {month-=days_of_a_month(y1,i);}
    day=d2-d1;
    return year+month+day;
}

int minute(){
    char a;
    int y1,m1,d1,h1,min1,y2,m2,d2,h2,min2;
    int day,min;
    cin >> y1 >> a >> m1 >> a >> d1 >> a >> h1 >> a >> min1;
    cin >> y2 >> a >> m2 >> a >> d2 >> a >> h2 >> a >> min2;
    day=sjc(y1,m1,d1,y2,m2,d2);
    min=(h2-h1)*60+(min2-min1);
    min+=day*60*60;
    return min;
}

int main(){
    int n,time,sum=0;
    cin >> n;
    for(int i=0; i<n; i++) cin >> a[i];
    time=minute();
    sort(a,a+n);
    for(int i=0; ; i++){
        if(time>=a[i]){time-=a[i]; sum++;}
        else break;
    }
    cout << sum;
    return 0;
}

|