1028. 人口普查(20):结构体比较大小
2015-05-17 15:38
267 查看
注意 输入的日期都不合理的情况···
5月17日版
——————————————————————————————————————————————————————
哈尔滨传来喜讯!
二等奖!
真棒!
8月14日版
——————————————————————————————————————————————————————
哈尔滨传来喜讯!
二等奖!
真棒!
5月17日版
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct Person { char Name[6]; int Year, Month, Day; }; bool Greater( Person a, Person b )//a的年龄大于b { if( a.Year != b.Year ) return a.Year < b.Year; else if( a.Month != b.Month ) return a.Month < b.Month; else return a.Day <= b.Day; } bool Less( Person a, Person b )// a的年龄小于b { if( a.Year != b.Year ) return a.Year > b.Year; else if( a.Month !=b.Month ) return a.Month > b.Month; else return a.Day >= b.Day; } int main() { int N, Count = 0; Person P, Max, Min, upper, lower; upper.Year = Max.Year = 2014; upper.Month = Max.Month = 9; upper.Day = Max.Day = 6; lower.Year = Min.Year = 1814; lower.Month = Min.Month = 9; lower.Day = Min.Day = 6; cin>>N; for( int i=0; i<N; i++ ) { scanf("%s %d/%d/%d", &P.Name, &P.Year, &P.Month, &P.Day); if( Greater(P,upper) && Less(P,lower) ) { Count++; if( Greater(P,Max) ) Max = P; if( Less(P,Min) ) Min = P; } } if(Count==0) cout<<0<<endl; else cout<<Count<<" "<<Max.Name<<" "<<Min.Name<<endl; return 0; }
——————————————————————————————————————————————————————
哈尔滨传来喜讯!
二等奖!
真棒!
8月14日版
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<vector> using namespace std; const int Size=1e5; struct node { string name; int y, m, d; node(string nme, int yy, int mm, int dd):name(nme), y(yy), m(mm),d(dd){} }; vector<node>vec; bool cmp(node n1, node n2) { if(n1.y!=n2.y) return n1.y<n2.y; if(n1.m!=n2.m) return n1.m<n2.m; return n1.d<n2.d; } int main() { int N; string name; int y, m, d; char c; cin>>N; int cnt=0; while(N--) { cin>>name>>y>>c>>m>>c>>d; if(y>2014||(y==2014&&m>9)||(y==2014&&m==9&&d>6)) continue; if(y<1814||(y==1814&&m<9)||(y==1814&&m==9&&d<6)) continue; vec.push_back(node(name, y, m, d)); cnt++; } sort(vec.begin(), vec.end(), cmp); if(cnt==0) cout<<0<<endl; else cout<<cnt<<" "<<vec[0].name<<" "<<vec[vec.size()-1].name<<endl; return 0; }
——————————————————————————————————————————————————————
哈尔滨传来喜讯!
二等奖!
真棒!
相关文章推荐
- 1028. 人口普查(20)
- PATB1028.人口普查(20)
- 1028. 人口普查(20)
- PAT 1028. 人口普查(20)
- PAT乙级 1028. 人口普查(20)
- PAT 乙级 1028. 人口普查(20)
- PAT乙级 1028. 人口普查(20)--字符串的妙用,两种方法解答
- 1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)--Python
- 1028. 人口普查(20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)
- 1028. 人口普查(20)(C++)