Millet 2017 Autumn recruit real problem--phone number of Fen (Java edition)

Source: Internet
Author: User

The original title is described as follows:

Through the analysis of the English words corresponding to each number, some rules can be found:

The letter Z is 0 exclusive, the letter W is 2 exclusive, the letter U is 4 exclusive, the letter X is 6 exclusive, the letter G is 8 exclusive;

After filtering over 0, 2, 4, 6, 8, the letter O is 1 exclusive, the letter H is 3 exclusive, the letter F is 5 exclusive, the letter S is 7 exclusive;

After filtering again 0, 1, 2, 3, 4, 5, 6, 7, 8, the remaining I is only 9 exclusive.

Therefore, based on the above rules, write the following processing code: (Java Version)

1 Importjava.util.ArrayList;2 Importjava.util.Arrays;3 Importjava.util.List;4 ImportJava.util.Scanner;5 6  Public classMinumber {7 8      Public Static voidMain (string[] args) {9Scanner in =NewScanner (system.in);Ten         intn =in.nextint (); Onestring[] arr =NewString[n]; AIn.nextline ();//First Call nextline () to discard the remainder of the line -          for(inti=0;i<n;i++) -Arr[i] =in.nextline (); the          - GetResult (N,arr); - in.close (); -     } +      -      Public Static voidGetResult (intn,string[] arr) { +          for(inti=0;i<n;i++){ AList<string> Numberc =NewArraylist<string>(Arr[i].length ()); at              for(intJ=0;j<arr[i].length (); j + +) -Numberc.add (Arr[i].charat (j) + ""); - GetNumber (NUMBERC); -NUMBERC =NULL; -         } -     } in      -      Public Static voidGetNumber (list<string>Numberc) { toStringBuilder SB =NewStringBuilder (); +         if(Numberc.size () >=4&&numberc.contains ("Z")) {//the letter Z is 0 exclusive -Sb.append ("2");//2+8 = 10, take digit 0, is the smallest number theNumberc.remove ("Z"); *Numberc.remove ("E"); $Numberc.remove ("R");Panax NotoginsengNumberc.remove ("O"); -         } the         if(Numberc.size () >=3&&numberc.contains ("W")) {//the letter W is 2 exclusive +Sb.append ("4");//4+8 = 12, take digit 2, is the smallest number ANumberc.remove ("T"); theNumberc.remove ("W"); +Numberc.remove ("O"); -         } $         if(Numberc.size () >=4&&numberc.contains ("U")) {//the letter U is 4 exclusive $Sb.append ("6");//6+8 = 14, take digit 4, is the smallest number -Numberc.remove ("F"); -Numberc.remove ("O"); theNumberc.remove ("U"); -Numberc.remove ("R");Wuyi         } the         if(Numberc.size () >=3&&numberc.contains ("X")) {//the letter X is 6 exclusive -Sb.append ("8");//8+8 = 16, take digit 6, is the smallest number WuNumberc.remove ("S"); -Numberc.remove ("I"); AboutNumberc.remove ("X"); $         } -         if(Numberc.size () >=5&&numberc.contains ("G")) {//the letter G is 8 exclusive -Sb.append ("0");//0+8 = 8, take digit 8, is the smallest number -Numberc.remove ("E"); ANumberc.remove ("I"); +Numberc.remove ("G"); theNumberc.remove ("H"); -Numberc.remove ("T"); $         } the         if(Numberc.size () >=3&&numberc.contains ("O")) {//letter O for 1 excluding 0,2,4,6,8 after exclusive theSb.append ("3");//3+8 = 11, take digit 1, is the smallest number theNumberc.remove ("O"); theNumberc.remove ("N"); -Numberc.remove ("E"); in         } the         if(Numberc.size () >=5&&numberc.contains ("H")) {//the letter H for 3 excludes 0,2,4,6,8 after exclusive theSb.append ("5");//3+8 = 11, take digit 1, is the smallest number AboutNumberc.remove ("T"); theNumberc.remove ("H"); theNumberc.remove ("R"); theNumberc.remove ("E"); +Numberc.remove ("E"); -         } the         if(Numberc.size () >=4&&numberc.contains ("F")) {//letter F for 5 excluding 0,2,4,6,8 after exclusiveBayiSb.append ("7");//7+8 = 15, take digit 5, is the smallest number theNumberc.remove ("F"); theNumberc.remove ("I"); -Numberc.remove ("V"); -Numberc.remove ("E"); the         } the         if(Numberc.size () >=5&&numberc.contains ("S")) {//letter F for 7 excluding 0,2,4,6,8 after exclusive theSb.append ("9");//9+8 = 17, take digit 7, is the smallest number theNumberc.remove ("S"); -Numberc.remove ("E"); theNumberc.remove ("V"); theNumberc.remove ("E"); theNumberc.remove ("N");94         } the         if(Numberc.size () >=4&&numberc.contains ("I")) {//letter F for 7 excluding 0,2,4,6,8 after exclusive theSb.append ("1");//1+8 = 9, take digit 9, is the smallest number theNumberc.remove ("N");98Numberc.remove ("I"); AboutNumberc.remove ("N"); -Numberc.remove ("E");101         }102         103String StrN =sb.tostring ();104         Char[] cr =Strn.tochararray (); the Arrays.sort (CR);106String result =string.valueof (CR);107         108 System.out.println (result);109     } the 111}

Millet 2017 Autumn recruit real problem--phone number of Fen (Java edition)

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.