How to extract non-repeating integers by Java
This article introduces the knowledge of "how to extract non-repeating integers from Java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Topic description
Enter an int integer and return a new integer without repeating numbers in right-to-left reading order.
Enter a description:
Enter an int integer
Output description:
Returns a new integer without repeating numbers in right-to-left reading order
Input example:
9876673
Examples of output:
376892. Program 1
Basic idea: set the initial value to 0, then read the output equal to 0, and then add 1 to the base value, that is, the next step is to compare the equal output with 1, so as to avoid repetition.
# include#includeusing namespace std;int main () {int a [10] = {0}; string str; getline (cin,str); int num = str.size (); int i; for (iint [I] -) {if (a [stri] -'0'] = = 0) {coutn; set temp; queue res While (n) {if (temp.find (n) = = temp.end ()) {res.push (n); temp.insert (n);} nAccord 10 } while (! res.empty ()) {coutstr) / / wait for the input to end / / of course, this step can be replaced by the getline () and for () loops, that is, getline (cin,str) to get the input, and then for (int iTunes ()) {/ / for (int i=str.length ()-1) > = 0 The starting position is str.size ()-1 instead of str.size (), and the end point is 0 instead of 1. The subscript size () is out of bounds (subscript starts at 0) if (map_input.find (strI)! = map_input.end ()) {/ / use the find function to locate the location of the data It returns an iterator, when the data appears, it returns the iterator of the location of the data. If there is no data to find in map, the iterator returned is equal to the iterator returned by the end function / / compare the last one as the benchmark value, that is, key selects the element has.end () [strI] + +. / / if something equal to the reference value is found, add the value corresponding to the key by 1} else {map_ input [str[ I] = 1 / / No key,value equal to the reference value is 1. Our value outputs key cout with a value of 1.