if wrong, hope can give me a message, thank you.
Topic Details (Java only)
Given a string of integers, you can only do two things: either an integer is placed before the string, or after the string. All integers are not equal.
Ask for the minimum number of operations required to turn this string of integers into a small-to-large order.
Input format:
Multiple sets of data, 1 rows per set of data, containing several whitespace-delimited nonnegative integers, not exceeding 2147483647 per integer.
Output format:
Each set of data output lines contains an integer that represents the number of times the minimum action is required.
Answer Instructions
Input sample
1 2 3
1 4 2
10 2 1
Sample output:
0
1
2
Algorithm parsing:
The length is the maximum length of the sequence of the original array ( subsequence ) and the ordered array ( contiguous subsequence ).
Import Java.util.scanner;public class Paixu {public static void main (string[] argv) {Scanner br =new Scanner (system.in); string[] k;k = new String[100];int num=0; Gets the number of rows between the input digits separated by a space line less than 100do {K[num] = Br.nextline (); if (K[num].equals (")") {break; } num++; } while (true); Br.close (); for (int i=0;i<num;i++) {int max=1; String[] Sf=k[i].split (""); int[] S,e;s=new int[sf.length];e=new int[sf.length];//converts each line of characters obtained into an int array e[] s[]; two arrays are the same. for (int m=0;m<sf.length;m++) {s[m]=integer.parseint (sf[m]); E[m]=integer.parseint (Sf[m]);} Bubble sort array s[]for (int j=0;j<sf.length-1;j++) {for (int p=0;p<sf.length-1-j;p++) {if (e[p]>e[p+1]) {int tmp=e[p]; e[p]=e[p+1];e[p+1]=tmp;}}} Assign an ordinal array e[] to the sequence number of each value in the original array s[] (int j=0;j<sf.length;j++) {for (int p=0;p<s.length;p++) {if (E[j]==s[p]) {E[j] =p;break;}}} int temp=1;//assigns the length of the longest continuous growth sequence in e[] to maxfor (int j=0;j<e.length-1;j++) {if (E[j+1]>e[j]) temp++;elsetemp=0;if (temp >max) Max=temp;} int Out=e.length-max; System.out.priNtln ("The Minimum Change:" +out);}}
Effect Demo:
China Telecom wing pay 2014 programming Contest final of my opinion (if wrong, hope to testify)