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

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

1055. The World's Richest (25)

2019-11-11 02:31:45
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柳江县| 衡阳市| 涡阳县| 宿迁市| 潍坊市| 手机| 平邑县| 琼结县| 隆德县| 乌拉特后旗| 浏阳市| 景谷| 城固县| 同心县| 万源市| 深圳市| 都江堰市| 微博| 金堂县| 哈尔滨市| 营山县| 成武县| 崇州市| 措美县| 闽侯县| 大邑县| 砚山县| 西宁市| 二连浩特市| 兴海县| 大兴区| 太原市| 含山县| 铜鼓县| 东兰县| 葫芦岛市| 融水| 西平县| 九江县| 宜兴市| 林口县|