Container-implemented text query Program

Source: Internet
Author: User

--------- The example on C ++ primer is implemented by yourself.

The program can read any text file specified by the user and then allow the user to find words from the file. The query result shows the number of times a word appears and lists the rows that appear each time. If a word appears multiple times in the same row, the program displays this row only once. The row number is displayed in ascending order.

1) it must allow users to specify the name of the file to be processed. The program will store the content of the file so that the original line of each word can be output.

2) It must break each line into different words and record the row of each word. When outputting a row number, ensure that the output is in ascending order and there are no duplicates.

3) A Query of a specific word returns the row number of all rows of the word.

4) when outputting the text row of a word, the program must be able to obtain the corresponding row from the input file based on the given row number.

1) Use a vector <string> type object to store copies of the entire input file. Each row of the input file is an element of the vector object.

2) store the row numbers of each word in a set container object. Using set ensures that each row has only one entry, and the row numbers are automatically sorted in ascending order.

3) Use a map container to associate each word with a set container object, which records the row number of the word.

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.