买房与卖房

不是我写的, 不过投个转载我又没有链接可写

#include <bits/stdc++.h>
using namespace std;
int m;
struct P
{
	char id[19];
	int social;
	int area;
	char date[11];
	bool operator<(const P &b) const
	{
		if (area == 0 && social <= 24)
			return 0;
		if (b.area == 0 && b.social <= 24)
			return 1;
		if (area != b.area)
			return area < b.area;
		if (area == 0 && social != b.social)
			return social > b.social;
		for (int i = 6; i < 10; ++i) //时间排序
			if (date[i] != b.date[i])
				return date[i] < b.date[i];
		for (int i = 0; i < 2; ++i)
			if (date[i] != b.date[i])
				return date[i] < b.date[i];
		for (int i = 3; i < 5; ++i)
			if (date[i] != b.date[i])
				return date[i] < b.date[i];
		return 0;
	}
};
P *p;
P *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);
	P *tmp = new P[n];
	fread(tmp, sizeof(P), n, fp);
	fclose(fp);
	return tmp;
}
int n;
map<string, int> mp;
void work()
{
	char c[19];
	scanf("%s", c);
	string s = c;
	int id = mp[s];
	int l = lower_bound(p, p + n, p[id]) - p + 1;
	int r = upper_bound(p, p + n, p[id]) - p;
	if ((p[id].area == 0 && p[id].social <= 24) || l > m)
		printf("Sorry\n");
	else if (l == r)
		printf("%d\n", l);
	else
		r > m ? printf("%d/%d\n", m - l + 1, r - l + 1) : printf("%d %d\n", l, r);
}
int main()
{
	p = getMess(n);
	sort(p, p + n);
	for (int i = 0; i < n; ++i)
	{
		string s = p[i].id;
		mp[s] = i;
	}
	int T;
	scanf("%d%d", &m, &T);
	while (T--)
		work();
	return 0;
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值