1028. 人口普查(20)自己写

/*




5
John 2001 05 12
Tom 1814 09 06
Ann 2121 01 30
James 1814 09 05
Steve 2007 11 20
*/




#include<iostream>
#include<string>


using namespace std;
int  main()
{


int n;
cin>>n;


string name;
int year,month,day;
int count=0;
string max,min;
int ty=0,tm=0,td=0;
int xy=9999,xm=99,xd=99;





for(int i=0;i<n;i++)
{
cin>>name;


cin>>year>>month>>day;



//<<name<<" "<<year<<month<<day;


//2014 9 6


//200 年前的不合格
if( year<1814 ||   ( year==1814 &&  month<9  )   ||   ( ( year==1814 &&  month==9  )  && day<=6  )  ){ continue;}


//未出生的 不合格
else if( year>2014 ||   ( year==2014  &&  month>9  ) ||  ( ( year==2014  &&  month==9  )    && day>=6 )  ){continue;}




else 
{
//取
if( year>ty ||   ( year==ty  &&  month>tm  ) ||  ( ( year==ty  &&  month==tm  )    && day>=td )      )
{
max=name;
ty=year;tm=month;td=day;
}






if( year<xy ||   ( year==xy &&  month<xm  )   ||   ( ( year==xy &&  month==xm  )  && day<=xd  )  )
{
min=name;
xy=year;xm=month;xd=day;
}




count++;
}






}


cout<<count<<" "<<max<<" "<<min;




return 0;
}
### 关于人口普查的C++编程示例 在处理人口普查数据时,通常会涉及到大量的数据分析操作。下面提供一段简单的C++代码用于模拟基本的人口普查数据收集和统计功能。 #### 定义人口普查记录结构体 为了存储个人的信息,在此定义了一个`PersonRecord`结构体来保存每个人的年龄、性别和地区信息: ```cpp #include <iostream> #include <vector> #include <string> struct PersonRecord { std::string name; int age; char gender; // 'M' for male, 'F' for female std::string region; PersonRecord(std::string n, int a, char g, std::string r) : name(n), age(a), gender(g), region(r) {} }; ``` #### 创建并填充人口普查数据库 接下来创建一个函数用来初始化一组虚拟的人口普查数据,并将其存入到容器中以便后续分析: ```cpp std::vector<PersonRecord> createPopulationData() { return { {"Alice", 30, 'F', "North"}, {"Bob", 25, 'M', "South"}, {"Charlie", 45, 'M', "East"}, {"Diana", 38, 'F', "West"} }; } ``` #### 统计特定条件下的统计数据 这里展示如何计算某个区域内男性人数以及平均年龄的例子: ```cpp void analyzeDemographics(const std::vector<PersonRecord>& population) { double totalAge = 0; size_t countMaleInRegion = 0; const auto& targetRegion = "East"; // 可以更改为其他地区 for (const auto& person : population) { if (person.region == targetRegion && person.gender == 'M') { ++countMaleInRegion; totalAge += person.age; } } if (!countMaleInRegion) { std::cout << "No males found in the specified region." << std::endl; } else { std::cout << "Number of males in '" << targetRegion << "' is " << countMaleInRegion << ". Average age: " << static_cast<double>(totalAge)/countMaleInRegion << "." << std::endl; } } int main() { auto popData = createPopulationData(); analyzeDemographics(popData); return 0; } ``` 这段程序展示了如何利用C++中的标准库特性(如字符串处理、向量容器等),实现对人口普查数据的基本管理和查询功能[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值