蒟蒻求助

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:08:47

@resftlmuttmotw 改变量就OK了??


by Forest_Prince @ 2019-11-01 23:21:09

@resftlmuttmotw 哭辽,答案都不对。。


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

@resftlmuttmotw WA


by resftlmuttmotw @ 2019-11-01 23:25:50

@Forest_Prince

要我帮忙DEBUG?


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

@resftlmuttmotw !!?


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

@resftlmuttmotw 大佬帮帮忙,没找到bug在哪啊


by resftlmuttmotw @ 2019-11-01 23:30:05

@Forest_Prince

那你等一会 我在看


by Forest_Prince @ 2019-11-01 23:30:57

@resftlmuttmotw 谢谢


by resftlmuttmotw @ 2019-11-01 23:46:00

@Forest_Prince

  #include<iostream>
    #include<algorithm>
    #define time t
    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 x){
        if(x%100==0){if(x%400==0)return 1;}
        else{if(x%4==0)return 1;}
        return 0;
    }
    int y1,y2,m1,m2,t1,t2,d1,d2,s1,s2; 
    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];
            }
        }
        time += -d1 + d2;
        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 resftlmuttmotw @ 2019-11-01 23:46:59

@Forest_Prince

  #include<iostream>
    #include<algorithm>
    #define time t
    关键字 
    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 x){
        if(x%100==0){if(x%400==0)return 1;}
        else{if(x%4==0)return 1;}
        return 0;
    }
    int y1,y2,m1,m2,t1,t2,d1,d2,s1,s2; 
    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];
            }
        }
        把以上的小于大于等于 改成了小于大于 
        time += -d1 + d2;
        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;
    }

| 下一页