国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1055. The World's Richest (25)

2019-11-11 01:19:44
字體:
來源:轉載
供稿:網友

1. 原題: https://www.patest.cn/contests/pat-a-PRactise/1055

2. 思路:

題意:根據給定的年齡范圍輸出財富排行榜。思路:數據處理題。不難,建結構體,按照要求排序。然后對符合范圍的遍歷輸出。注意:盡量不要用string,會超時。

3. 源碼(已AC):

#include<iostream>#include<algorithm>//使用sort函數#include<cstring>//使用strcmp函數using namespace std;struct Node//每個人的結構體{	bool Operator<(const Node &b) const//重載比較運算符	{		if (wea != b.wea)			return wea > b.wea;		else if (age != b.age)			return age < b.age;		else			return strcmp(name, b.name) < 0;	}	char name[10];//存儲名字	int age, wea;//分別為年齡, 財富};int main(void){	//freopen("in.txt", "r", stdin);	int N, K;	scanf("%d %d", &N, &K);	Node *pe = new Node[N];//存儲每個人的信息	for (int i = 0; i < N; i++)		scanf("%s %d %d", &pe[i].name, &pe[i].age, &pe[i].wea);	sort(pe, pe+N);//根據給定要求排序	for (int i = 0; i < K; i++)	{		printf("Case #%d:/n", i + 1);		int M, amin, amax;		scanf("%d %d %d", &M, &amin, &amax);				int cnt = 0;		for (int j = 0; j < N; j++)		{			if (pe[j].age >= amin && pe[j].age <= amax)//符合范圍的輸出			{				cnt++;				printf("%s %d %d/n", pe[j].name, pe[j].age, pe[j].wea);			}			if (cnt == M)				break;		}		if (cnt == 0)			printf("None/n");	}	delete[] pe;	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永宁县| 金寨县| 河源市| 友谊县| 时尚| 台前县| 隆德县| 盐城市| 台安县| 海宁市| 内黄县| 平果县| 华蓥市| 论坛| 城固县| 东光县| 中超| 巫溪县| 和平县| 陵川县| 辉县市| 历史| 衡阳市| 金秀| 横山县| 西乌珠穆沁旗| 崇义县| 南丰县| 洛扎县| 曲松县| 沈阳市| 洪洞县| 哈尔滨市| 喀喇| 聂拉木县| 三原县| 当涂县| 达州市| 九龙坡区| 枞阳县| 临漳县|