HNU软件能力实训1-8. 买房与选房

这篇博客介绍了HNU软件能力实训中的一个实战问题——如何在买房与选房中做出决策。内容涉及使用编程思维和算法来解决实际问题。
摘要由CSDN通过智能技术生成

远离这道题,会变得不幸

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;

struct People{
   //题给的结构体,注意该结构体不能修改,避免文件读取错误
    char id[19];                  /* 身份证号码 */
    int social;                     /* 社保缴纳月数 */
    int area;                       /* 现有住房面积 */
    char date[11];              /* 申报日期 */
};

struct people{
   //魔改的结构体
    string id;                  /* 身份证号码 */
    int social;                     /* 社保缴纳月数 */
    int area;                       /* 现有住房面积 */
    string date;              /* 申报日期 */
    int dateint=0;//日期拼接成的整数
    int rank=0;//排名
    int samerank=0;//并列排名的人数
};

vector<string> split(string s,string separate){
   //字符串分段函数
    vector<string> splited;
    unsigned int separate_len=separate.length();
    unsigned int start=0;
    int index;
    while((index=s.find(separate,start))!=-1){
   
        splited.push_back(s.substr(start,index-start));
        start=index+separate_len;
    }
    if(start<s.length()){
   
        splited.push_back(s.substr(start,s.length()-start));
    }
    return splited;
}

bool compare1(people data1,people data2){
   //刚性需求自定义排序
    if (data1.social==data2.social){
   
        return data1.dateint < data2.dateint;
    }
    else{
   
        return data1.social>data2.social;
    }
}

bool compare2(people data1,people data2){
   //改善性需求自定义排序
    if (data1.area==data2.area){
   
        return data1.dateint < data2.dateint;
    }
    else{
   
        return data1.area<data2.area;
    }
}

People* getMess(int &n){
   //题给的读文件函数
    FILE* fp;
    fp=fopen("house.bin","rb");
    fseek(fp,-1*(long)sizeof(int), 2);
    fread(&n, sizeof(int),1, fp);
    rewind(fp);
    People
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值