The question description counts the number of occurrences of the different words in the English article paragraph (the word has a case, but the case is ignored when the statistics are written). The total number of words in the input paragraph does not exceed 100, and the maximum word length does not exceed 20 letters. Input format a paragraph containing several sentences, each of which consists of several English words. In addition to spaces, commas, and periods, these input sentences do not contain other non-alphabetic characters, and commas and periods immediately follow the English word in front of it, with no spaces in the middle. The last character of the paragraph is the carriage return, which indicates the end of the input. Output format if the paragraph has m different English words, then it will output m lines according to the order in which they appear in the paragraph, the format of each line is: all letters in the word are output in uppercase (the longest word shelf output, it has no extra space in front; The remaining words are aligned to the right) + colon +n * + the number of occurrences of the word in a paragraph n sample input
This is a test. This test was easy. This is a test. This test was easy.
Sample output
This:****4is:****4a:**2test:****4easy:**2
1 ImportJava.util.LinkedHashMap;2 ImportJava.util.Map;3 ImportJava.util.Scanner;4 5 Public classmain{6 Static intN;7 Static inth;8 Public Static voidMain (string[] args) {9Scanner input =NewScanner (system.in);TenString A =input.nextline (); OneString[] B = A.split ("|, |\\. | \\."); AMap<string, integer> m =NewLinkedhashmap (); - for(inti=0;i<b.length;i++){ -B[i] =b[i].tolowercase (); the } - for(inti=0;i<b.length;i++){ - if(M.containskey (B[i])) { -M.put (B[i], M.get (B[i]) +1); +}Else{ -M.put (B[i], 1); + } A } at for(String s:m.keyset ()) { -System.out.print (S.touppercase () + ":"); - for(intI=0;i<m.get (s); i++){ -System.out.print ("*"); - } - System.out.println (M.get (s)); in } - } to}
Blue Bridge Cup Java algorithm improves statistical word count