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

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

1055. The World's Richest (25)

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

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐城市| 绥滨县| 澎湖县| 仙游县| 天峻县| 定西市| 伊川县| 厦门市| 秭归县| 罗城| 巴楚县| 莱州市| 江西省| 龙里县| 高阳县| 正阳县| 南川市| 拉孜县| 东乡族自治县| 瓮安县| 贺州市| 保靖县| 新干县| 屯门区| 隆林| 武平县| 阜城县| 西盟| 汉寿县| 敦煌市| 营口市| 昌邑市| 永泰县| 十堰市| 婺源县| 托克托县| 冀州市| 莱阳市| 长春市| 崇文区| 曲松县|