Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write the Python text query code

Shulou Source: shulou.com Published: 2022-06-01 01:05:56 09月20日 Update

This article mainly explains the "Python text query code how to write", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python text query code how to write" it!

/ / text query

/ / what needs to be done

/ / 1. Put each line of a text into the vector.

/ / 2. Record the line number of each word

/ / 3. Output each line of words according to the line number.

Class TextQuery

{

Public:

Typedef vector::size_type line_no

Void store_file (ifstream& is)

Setprint_lineno (string&) const

Stringprint_linestring (line_no) const

Private:

Vectorline_of_text

Mapword_map

}

Void TextQuery::store_file (ifstream& is)

{

String word

While (getline (is,word))

{

Line_of_text.push_back (word)

}

Line_no num

For (num=0; num! = line_of_text.size (); + + num)

{

String line, tempword

Istringstream istream (line_of_ text [num])

While (istream > > word)

{

Word_ map [word] .insert (num)

}

}

}

Set TextQuery::print_lineno (string& str)

{

Map::iterator iter = word_map.find (str)

If (iter = = word_map.end ())

{

Return set ()

}

Return iter- > second

}

String TextQuery::print_linestring (line_no num)

{

If (num < line_of_text.size ())

{

Return line_of_ text[num]

}

}

Void print_result (const set& los, const string& str, const TextQuery & textclass)

{

Cout

Tags: Text query code learning content words line numbers one line things that is ideas situations articles more knowledge knowledge points articles follow questions practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Xiaomi Microsoft macOS