L1-027. Rent, l1-027 rent

Source: Internet
Author: User

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("};");    }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.