pat 1028 人口普查

题目:

 我的代码:(并没有完全`通过,测试四没通过`,答案错误`)

代码如下:

#include<cstdio>
#include<cstring>
#include<iostream> 
#include<algorithm>
using namespace std;
int sum=0,a=2014,b=9,c=6,q=0,p=0,r=0;
bool x(int y,int m,int d){
    if(y>2014) return false;
    if(y==2014&&m>9) return false;
     if(y==2014&&m==9&&d>6) return false;
     if(y<2014&&m<9&&2014-y>=200) return false;
     if(y<2014&&m>9&&2014-y-1>=200) return false;
     if(y<2014&&m==9&&d<6&&2014-y>=200) return false;
     if(y<2014&&m==9&&d>=6&&2014-y-1>=200) return false;
     return true;
}
int f(int y,int m,int d){
    if(y==2014&&m<9){
    sum=1;    
    return sum;
    }
    if(y==2014&&m==9&&d<6){
        sum=1;    
    return sum;
    }
    if(m<9) {
    sum=2014-y ;
      return sum;    
    }
    if(m==9&&d<6) {
    sum=2014-y;return sum;    
    }
//    return sum-1;
else {
    sum=2014-y-1;
    return sum;    
        }
}
int main(){
    
//ios::sync_with_stdio(false);
//cin.tie(0);
    int n,y,m,d,count=0,max=0,min=200;
    string k,s,e;
//    scanf("%d",&n);
cin>>n; 
    while(n--){
        cin>>s;
        scanf("%d/%d/%d",&y,&m,&d)    ;
//cin>>y>>m>>d;
        if(x(y,m,d)){
        count++;}
        if(x(y,m,d)){
        if(max<f(y,m,d)){
            if(y<=a||m<=b||d<=c){
        max=f(y,m,d);
        e=s;
        a=y;
        b=m;
        c=d;    
        }        
            }
            
        }
        if(x(y,m,d)){
        if(min>f(y,m,d)){
            if(y>=q||m>=p||d>=r){
        min=f(y,m,d);
        k=s;    
        q=y;
        p=m;
        r=d;    
            }
        }    
        }
    }
if(count!=0){
//    printf("%d ",count);
cout<<count<<" ";
    cout<<e<<" ";
    cout<<k;
}
else cout<<"0";
    
}

同时为比较奇怪的是为什么我在`主函数加入了//ios::sync_with_stdio(false);
//cin.tie(0);
答案却和不加会有变化????

无聊就学习 反正没事干
原文地址:https://www.cnblogs.com/miao-xixixi/p/12535473.html