1102. Teaching Super Championship Paper (20 points)

"Education Supermarket" is a derivative product of Puzzle A system, which releases various test papers and exercises for users to purchase. In the list of test papers, the system not only lists the unit price of each test paper, but also shows the current number of purchasers. In this question, you are asked to find out the sales (that is, the number of purchases) champion and the sales champion in all the test papers of the education supermarket based on this information.

Input format:

Input firstly give a positive integer N (≤104) in the first line, followed by N lines, each line gives a unique ID of a paper (a string composed of lowercase letters and numbers, the length of which does not exceed 8 digits) , unit price (a positive integer not exceeding 100) and number of purchases (a non-negative integer not exceeding 106).

Output format:

Output the ID of the sales champion and its sales in the first row, and output the ID and sales of the sales champion in the second row. Lines of output are separated by a space. The title guarantees that the champion is unique and there is no tie.

Input sample:

4
zju007 39 10
pku2019 9 332
pat2018 95 79
qdu106 19 38

Sample output:

pku2019 332
pat2018 7505

Be careful not to initialize it to 0, the sales volume may be 0, or you can use greater than or equal to judge.... step on the pit

#include<cstdio>
#include<set>
#include<map>
#include<cmath> 
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	string name;
	int price,num,N;
	string saleNumMax,saleTotalMax;
	int numMax=-1,totalMax=-1;
	cin>>N;
	while(N--){
		cin>>name>>price>>num;
		if(num>numMax){
			numMax = num;
			saleNumMax = name;
		}
		if(num*price>totalMax){
			totalMax = num*price;
			saleTotalMax = name;
		}
	}
	cout<<saleNumMax<<" "<<numMax<<endl;
	cout<<saleTotalMax<<" "<<totalMax<<endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_16382227/article/details/124042257