国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仁布县| 儋州市| 汨罗市| 新化县| 龙口市| 大名县| 惠来县| 曲周县| 佛山市| 邯郸市| 榆社县| 肥东县| 襄城县| 剑河县| 安宁市| 湘西| 手游| 通城县| 綦江县| 高密市| 宝坻区| 错那县| 常山县| 仁寿县| 灵石县| 望奎县| 商丘市| 嘉荫县| 通城县| 六安市| 翁牛特旗| 津南区| 贺兰县| 安平县| 丁青县| 鄱阳县| 迁西县| 焦作市| 民权县| 福鼎市| 那曲县|