Airline VIP customer inquiry (25 points)

Many airlines provide preferential membership services. When a customer has accumulated a certain number of flight miles, he can use his mileage to directly redeem award tickets or award upgrades. Given the flight records of all members of an airline, it is required to realize the function of quickly querying member mileage points based on the ID number.

Input format: The
input first gives two positive integers N (≤10​5​​) and K (≤500). Among them, K is the minimum mileage, that is, to take care of members who take short-haul flights, airlines will also accumulate flights with a range of less than K kilometers as K kilometers. Next N lines, each line gives a flight record. The input format of the flight record is: 18-digit ID number (space) flight mileage . The ID number is composed of 17 digits and the last check code. The value range of the check code is 0-9 and 11 symbols in total. The unit of flight mileage is kilometers, which is within the interval of (0, 15 000). An integer. Then give a positive integer M (≤10​5​​), and then give the ID number of the M line of the inquirer.

Output format:
For each query person, the current mileage accumulation value is given. If the person is not a member, No Info is output. Each query result occupies one row.

4 500
330106199010080419 499
110108198403100012 15000
120104195510156021 800
330106199010080419 1
4
120104195510156021
110108198403100012
330106199010080419
33010619901008041x
 800
15000
1000
No Info

Question idea: The map container came to my mind. The key lies in how to solve the problem of the timeout of the last two test points. Later, I searched the Internet and found that the speed of scanf is higher than that of cin. Secondly, this question requires 18 digits for the string length. If the string.resize(18) question is wrong at the beginning, the answer will be wrong.

#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string, int> mp;
int main()
{
    
    
	int n, k, t;
	string st;
	st.resize(18);
	scanf("%d %d", &n, &k);
	while (n--)
	{
    
    
		scanf("%s", &st[0]);
		scanf("%d", &t);
		mp[st] += t < k ? k : t;
	}

	int m;
	scanf("%d", &m);
	while (m--)
	{
    
    
		scanf("%s", &st[0]);
		if (mp[st] == 0)
			printf("No Info\n");
		else
			printf("%d\n", mp[st]);
	}


}

Guess you like

Origin blog.csdn.net/xdg15294969271/article/details/114077663