用容器存数组简单一些,字符串string好些
- 一个坑点就是没有有效生日,只输出0
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Node{
string name;
int y,m,d;
};
vector<Node> node;
bool cmp(Node a,Node b){
if(a.y!=b.y){
return a.y<b.y;
}else if(a.m!=b.m){
return a.m<b.m;
}else{
return a.d<b.d;
}
}
int main(){
int n;cin>>n;
while(n--){
string name;
cin>>name;
int y,m,d;
scanf("%d/%d/%d",&y,&m,&d);
if(y>1814&&y<2014){
node.push_back({name,y,m,d});
}
if(y==1814){
if(m>9){
node.push_back({name,y,m,d});
}
if(m==9&&d>=6){
node.push_back({name,y,m,d});
}
}
if(y==2014){
if(m<9){
node.push_back({name,y,m,d});
}
if(m==9&&d<=6){
node.push_back({name,y,m,d});
}
}
}
sort(node.begin(),node.end(),cmp);
if(node.size()==0){
cout<<node.size();
}else{
cout<<node.size()<<" "<<node[0].name<<" "<<node[node.size()-1].name;
}
return 0;
}