Blue Bridge Cup Java algorithm improves statistical word count

Source: Internet
Author: User

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

Related Article

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.