In the morning, I got an algorithm for high-precision power, and I was lazy using the internal class. I always felt that I was unwilling to do so. So today I made a new algorithm question, and I felt a lot more comfortable after I finished it.
The questions are as follows:
Enterprises like to use phone numbers that are easy to remember. One way to make phone numbers easy to remember is to write them into words or phrases that are easy to remember. For example, you can call TUT-GLOP when calling the University of Waterloo. Sometimes, only some numbers in the phone number are spelled into words. When you return to the hotel in the evening, you can call 310-GINO to order a pizza for Gino's. Another way to make phone numbers easy to remember is to group numbers in a memorable way. Call the "three dozen" numbers of pizza Hut 3-10-10-10, you can order pizza from them.
The input format is: the first line is a positive integer that specifies the number (up to 100000) in the phone number book ). The remaining line is a phone number. Each phone number consists of numbers, uppercase letters (except Q and Z), and connectors. Each phone number contains only seven digits or letters.
Output
Generates a line of output for each duplicate number. The output is the standard format of the number followed by a space and the number of duplicates. If multiple duplicate numbers exist, they are output in ascending order according to the number dictionary. If no duplicate numbers exist in the input data, output one line:
124873279ITS-EASY888-45673-10-10-10888-GLOPTUT-GLOP967-11-11310-GINOF101010888-1200-4-8-7-3-2-7-9-487-3279
487-3279 4888-4567 3310-1010 2967-1111 1310-4466 1888-1200 1
The Code is a little messy. Please click it.
Code:
Import java. util. arrayList; import java. util. extends; public class ThePhoneNum {public static void main (String args []) {String [] tem = new String [8]; // used to store the formatted phone number tem [3] = "-"; // set the fourth digit of the phone number to '-' ArrayList <String> list = new ArrayList <String> (); // record the invalid ArrayList number entered <String> memory = new ArrayList <String> (); // records all formatted numbers. in); int num = bytes. nextInt (); int [] count = New int [num]; // count the number of identical numbers while (num --)> = 0) {list. add (response. nextLine () ;}for (int I = 0; I <list. size (); I ++) {String string = list. get (I); String [] temparray = string. split ("-"); // remove all "-" string = getStr (temparray) from the input number ); // convert the string array obtained from the upstream code into a string for (int j = 0; j <string. length (); j ++) {String temString = string. substring (j, j + 1); if (j <3) {if (isLetter (temString) {// whether it is a letter tem [j] = toNum (te MString); // map letters to numbers} else {tem [j] = string. substring (j, j + 1); // do not map numbers} else {if (isLetter (temString) {tem [j + 1] = toNum (temString );} else {tem [j + 1] = string. substring (j, j + 1) ;}} if (tem [1]! = Null) {String s = getStr (tem); // Add the converted number to the list for storage if (memory. contains (s) {count [memory. indexOf (s)] ++; // if it already exists, add 1} else {memory. add (s) ;}}for (String s: memory) {System. out. println (s + "" + (count [memory. indexOf (s)] + 1); // traverse the list, output number} private static String toNum (String temString) {// TODO Auto-generated method stubchar c = temString. charAt (0); String s = String. valueOf (c); switch (c) {case 'A': case 'B': case 'C ': s = "2"; break; case 'D': case 'E': case 'F ': s = "3"; break; case 'G': case 'H': case 'I ': s = "4"; break; case 'J': case 'K': case 'l ': s = "5"; break; case 'M': case 'N': case 'O ': s = "6"; break; case 'p': case 'r': case's ': s = "7"; break; case 'T': case 'U': case 'V ': s = "8"; break; case 'W': case 'X': case 'y ': s = "9"; break;} return s;} static boolean isLetter (String s) {char c = s. charAt (0); if (c >=65 & c <= 122) {return true;} else {return false ;}} public static String getStr (String [] args) {String str = ""; for (int I = 0; I <args. length; I ++) {str + = (String) args [I] ;}return str ;}}
Author: jason0539
Weibo:
Blog: (For details, refer to the source)