【pat】rent

Here is a picture that was once very popular on Sina Weibo:

For a while, there were calls for help on the Internet, asking how to break this. In fact, this code is very simple, the index array is the subscript of the arr array, index[0]=2 corresponds to arr[2]=1, index[1]=0 corresponds to arr[0]=8, index[2]=3 Corresponding to arr[3]=0, and so on... It is easy to get the phone number is 18013820100.

This question requires you to write a program to generate this code for any phone number—in fact, you only need to generate the first two lines, and the following content remains unchanged.

Input format:

Enter a mobile number consisting of 11 digits given on one line.

Output format:

The first two lines of the code are generated for the entered number, where the numbers in arr must be given in descending order.

Input sample:

18013820100

Sample output:

int[] arr = new int[]{8,3,2,1,0};
int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};
It is still easy to understand the topic. Some operations in the middle have checked some functions to use
set<char, greater<char>> s; greater descending order set default ascending order
copy(s.begin(),s.end(),v1); //The elements within the specified range in the container are copied to another container.
Ideas:
1. Each number should be viewed separately, then we treat them as characters one by one.
2. Put the input number into the set collection to realize the function of deduplication + greater descending order to realize the first output (the character -'0' is converted into int type) 3. Put the
input number into the array, open an array with the capacity of the set collection, and put Copy the set collection to the array, and then open an array to store the subscripts.
4. Traverse the array of input numbers, and if the corresponding array of the set collection appears, save the subscript of the set collection array into the subscript array, and finally traverse the output.

AC:

Guess you like

Origin blog.csdn.net/m0_62504956/article/details/128618191
PAT