蒟蒻求助

P1167 刷题

Forest_Prince @ 2019-11-01 23:02:36

int time’被重新声明为不同意义的符号??

很疑惑

    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int MAXN=5000+50;
    int month1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int month2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int n,time,ans;
    int a[MAXN];
    char s;
    bool check(int a){
        if(a%4==0 && a%400!=0) return true;
        else if(a%400==0&&a%100==0) return  true;
        else return false;
    }
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        cin>>y1>>s>>m1>>s>>d1>>s>>t1>>s>>s1;//y1,m1,d1,t1,s1有用  
        cin>>y2>>s>>m2>>s>>d2>>s>>t2>>s>>s2;//y2,m2,d2,t2,s2有用 
        for(int i=y1;i<=y2;i++){
            if(check(i)){
                time+=366;
            }else time+=365;
        }
        if(check(y1)){
            for(int i=1;i<=m1;i++){
                time-=month2[i];
            }
        }else{
            for(int i=1;i<=m1;i++){
                time-=month1[i];
            }
        }
        if(check(y2)){
            for(int i=1;i<=m2;i++){
                time+=month2[i];
            }
        }else{
            for(int i=1;i<=m2;i++){
                time+=month1[i];
            }
        }
        for(int i=1;i<=d1;i++) time--;
        for(int i=1;i<=d2;i++) time++;
        time=time*24*60;
        time-=60*t1+s1;
        time+=60*t2+s2;
        int temp=time;
        for(int i=1;i<=n;i++){
            if(temp>=a[i]){
                temp-=a[i];
                ans++;
            }else break;
        }
        cout<<ans;
        return 0;
    }

不明所以蒟蒻求教


by Forest_Prince @ 2019-11-01 23:49:11

@resftlmuttmotw 为啥加了一个

time += -d1 + d2;


by Forest_Prince @ 2019-11-01 23:50:48

@resftlmuttmotw 哇!谢谢大佬!%%


by Forest_Prince @ 2019-11-01 23:52:38

@resftlmuttmotw AC了,谢谢大佬


by Forest_Prince @ 2019-11-01 23:54:56

@resftlmuttmotw 改成小于是因为取不到嘛?


上一页 |