Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the Python text query code

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report