L1-027. Rent, l1-027 rent
The following figure shows the popularity of Sina Weibo:
I had a cry for help on the Internet. I was anxious to ask how to solve this problem. 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 corresponds to arr [3] = 0, and so on ...... 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 subsequent content remains unchanged.
Input Format:
Enter an 11-digit mobile phone number in a row.
Output Format:
Generate the first two lines of code for the entered number. The numbers in arr must be in descending order.
Input example:
18013820100
Output example:
int[] arr = new int[]{8,3,2,1,0};int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};
Time limit 400 ms memory limit 65536 kB code length limit 8000 B discriminant program Standard author Chen Yue
import java.util.*;public class main { public static void main(String[] args) { int[] tel = new int[11]; int[] arr = new int[10]; int[] tel1 = new int[11]; int[] index = new int[11]; Scanner in = new Scanner(System.in); String l = in.next(); for(int i = 0; i < 11; i++) { tel[i]=(int)(l.charAt(i) - '0'); tel1[i]= tel[i]; } for(int i = 0; i < 11; i++) { int pos = i; for(int j = i+1; j < 11; j++) { if(tel1[j] > tel1[pos]) pos = j; } if(pos != i) { int temp = tel1[pos]; tel1[pos] = tel1[i]; tel1[i] = temp; } } int k = 0; arr[k]= tel1[0]; for(int i = 1; i < 11; i++) { if(arr[k] != tel1[i]) { k++; arr[k] = tel1[i]; } } for(int i = 0; i < 11; i++) { for(int j = 0; j <= k; j++) { if(tel[i] == arr[j]) { index[i] = j; } } } System.out.print("int[] arr = new int[]{"); System.out.print(arr[0]); for(int i = 1; i <= k; i++) { System.out.print("," + arr[i]); } System.out.println("};"); System.out.print("int[] index = new int[]{"); System.out.print(index[0]); for(int i = 1; i < 11; i++) { System.out.print("," + index[i]); } System.out.println("};"); }}