week8_1

1. Problem analysis

The question requires ① input n sets of data, each set of data has ten ② find the highest and lowest priority values ​​in all data ③ priority definition: P(a)>P(b), the number of prime factors of a is greater than b, The number of prime factors is the same, and the larger value has the higher priority.

First write a Factor() function to find the number of prime factors of a number. It should be noted that the prime factors do not include the value itself. For example, the number of prime factors of 3 is 0, not 1.

In the main function, I use the map<int, vector<int> > container, the key - the number of prime factors, the value - the corresponding number, the vector does not have a sorting function, so you have to sort it yourself. What is more laborious is that there is no way to directly delete, add, and sort the vector in the map container. You can only use tem to temporarily store and then completely cover it, which is inefficient. But the amount of code is almost the same as using a multiset container.

2. Solutions

①Factor() function, find the number of prime factors

②In the main function, first determine whether there is a corresponding value in the map, if not, you need to get a tem to store a value, and then insert it. If it exists, you need to figure out the array corresponding to the value, and then insert the number into it.

③ Find the minimum number in Map[begin] and the maximum number in Map[end-1]. Exist in re[2], delete it in the array and put it back into the Map container.

3. Algorithm design

4. Programming implementation

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325163979&siteId=291194637