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

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

1055. The World's Richest (25)

2019-11-11 00:59:25
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富锦市| 娄烦县| 仲巴县| 荃湾区| 大姚县| 台江县| 沛县| 万安县| 伊春市| 巴南区| 敦煌市| 交口县| 军事| 长治市| 崇仁县| 桦川县| 万山特区| 资源县| 柯坪县| 新宾| 柳江县| 饶阳县| 鲁山县| 漠河县| 垣曲县| 陆良县| 乐至县| 北京市| 社旗县| 福泉市| 昌乐县| 江西省| 祁阳县| 孟州市| 肥东县| 体育| 体育| 河东区| 万全县| 绥中县| 沂水县|