WA20pts求助

P1167 刷题

The_Wandering_Earth @ 2022-12-30 10:15:03

#include<bits/stdc++.h> 
using namespace std;
int n,times,ans,a[5010],m1[]={0,31,28,31,30,31,30,31,31,30,31,30,31},m2[]={0,31,29,31,30,31,30,31,31,30,31,30,31},start[10],endd[10];
bool check(int y){
    if(y % 400==0)return 1;
    if(y % 100==0)return 0;
    if(y % 4==0)return 1;
    return 0;
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i]; 
    sort(a+1,a+n+1);
    scanf("%d-%d-%d-%d:%d",&start[1],&start[2],&start[3],&start[4],&start[5]);
    scanf("%d-%d-%d-%d:%d",&endd[1],&endd[2],&endd[3],&endd[4],&endd[5]);
    for(int i=start[1];i<=endd[1];i++){
        if(check(i))times+=366;
        else times+=365;
    }
    if(check(start[1])){
        for(int i=1;i<start[2];i++){
            times-=m2[i];
        }
    }else{
        for(int i=1;i<start[2];i++){
            times-=m1[i];
        }
    }
    if(check(endd[1])){
        for(int i=1;i<endd[2];i++){
            times+=m2[i];
        }
    }else{
        for(int i=1;i<endd[2];i++){
            times+=m1[i];
        }
    }
    for(int i=1;i<start[3];i++)
        times--;
    for(int i=1;i<endd[3];i++)
        times++;
    times=times*24*60;
    times-=60*start[4]+start[5];
    times+=60*endd[4]+endd[5];
    for(int i=1;i<=n;i++){
        if(times>=a[i])times-=a[i],ans++;
        else break;
    }
    cout<<ans;
}

by 编码落寞 @ 2022-12-30 10:21:43

@zhangpeinan123

 for(int i=start[1];i<=endd[1];i++){

你把<=改成<,能过样例


by The_Wandering_Earth @ 2022-12-30 10:25:41

@编码落寞 感谢,我先试试


by The_Wandering_Earth @ 2022-12-30 10:26:41

@编码落寞 ac了,感谢


|