string algorithm 1

C++中的boost::iterator_range详解及测试程序 boost::iterator_range是Boost库中的一个非常有用的工具,用于处理迭代器范围。它提供了一种简单而灵活的方式来操作范围内的元素。boost::iterator_range是Boost库中的一个非常有用的工具,用于处理迭代器范围。在这个示例程序中,我们创建了一个std::vector容器,并使用boost::iterator_range封装了容器的迭代器范围。在此示例程序中,我们创建了一个std::vector容器,并使用boost::iterator_range封装了容器的迭代器范围。 阅读详情
简介

string algorithm是boost中提供字符串算法的类库。在这里,字符串不一定是std::basic_string,也可以是其它的stl容器或是c++中的零结尾字符串char*。

例:

std::string str("Hello");

std::vector<char> vstr(str.begin(), str.end());

char *cstr=new char(str.size());

std::copy(str.begin(), str.end(), cstr);

    

boost::to_upper(str);       //string

boost::to_upper(vstr);  //vector<char>

boost::to_upper(cstr);  //char*

 

另外,在string algorithm中的很多算法都分为mutable 和copy,mutable算法直接修改输入的字符串,而copy算法返回一个新的字符串或通过一个迭代器输出。

在string algorithm中碰到一个IteratorRange的概念,这是boost::range中的一个类,我也不会使用,不过可以使用make_iterator_range(iterator, iterator)来构造。iterator_range通过两个开始和结束迭代器表示一段范围,一般通过查找算法的返回来得到。

例:

std::string str1("Hello");

std::string str2("Hello");

 

boost::to_upper(str1);//mutable algorithm,现在str1==”HELLO”

 

std::string str3=boost::to_upper_copy(str2);//copy algorithm, str3==”HELLO”

/*

char * p =boost::to_upper_copy("Hello");

这是错的。因为to_upper_copy不会去申请一段内存保存"Hello"的拷贝。

char str[]={"Hello"};

to_upper(str);这样这就可以了。

*/

    

std::string str4;

    

 

boost::to_upper_copy(std::back_inserter(str4),

                    std::make_pair(str2.begin(), str2.end())

                    );//使用迭代器的copy algorithm, str4==”HELLO”

                      //这里注意,这里和stl不同的是输出迭代器在输入迭代器的前面

boost::to_upper_copy(std::back_inserter(str4), "Hello");str4==”HELLOHELLO”

//这也是可以的,前面说过了IteratorRange相当于一个容器,

//stl标准容器,std::basic_string 和char*都可以作为string_algorithm中的容器

Case Conversion Algorithm 大小写转换算法

void           to_lower(MutableCollection&, std::local&=std::local());

void           to_upper(MutableCollection&, std::local&=std::local());

 

Sequence       to_lower_copy(const Sequence&, std::local&=std::local());

Sequence       to_upper_copy(const Sequence&, std::local&=std::local());

 

OutputIterator to_lower_copy(OutputIterator, const Collection&, std::local&=std::local());

OutputIterator to_lower_copy(OutputIterator, const Collection&, std::local&=std::local());

 

在string algorithm中,Collection指:

l         stl标准类型

l         内建数组(如:int[])

l         零结尾字符串(char*或wchar *)

l         pair<iterator, iterator>

MutableCollection当然是指非const 的collection。

Sequence好像只能是标准容器。

 

Trim Algorithm Trim算法

void trim       (Sequence&, std::local&=std::local());

void trim_left  (Sequence&, std::local&=std::local());

void trim_right (Sequence&, std::local&=std::local());

 

Sequence trim_copy        (const Sequence&, std::local&=std::local());

Sequence trim_left_copy  (const Sequence&, std::local&=std::local());

Sequence trim_right_copy (const Sequence&, std::local&=std::local());

上述算法删除字符串中左右(或是其中之一)的空格。

 

void trim_if      (Sequence&, Predicate);

void trim_left_if (Sequence&, Predicate);

void trim_right_if(Sequence&, Predicate);

 

Sequence trim_copy_if      (const Sequence&, Predicate);

Sequence trim_left_copy_if (const Sequence&, Predicate);

Sequence trim_right_copy_if(const Sequence&, Predicate);

 

OutputIterator trim_copy_if      (OutputIterator, const Collection&, Predicate);

OutputIterator trim_left_copy_if (OutputIterator, const Collection&, Predicate);

OutputIterator trim_right_copy_if(OutputIterator, const Collection&, Predicate);

上述算法删除字符串左右(或是其中之一)满足Predicate的字符。

Predicate是一个一元判断式。

例:

string str(“---Hello---”);

boost::trim_if(str, bind2nd(equal_to<char>(), ’-‘));//str==”Hello”

 

Predicate 判断式

string algorithm中提供了一些与字符串相关的判断式。

bool starts_with (Input, Test);

bool starts_with (Input, Test, Comp)

bool istarts_with(Input, Test, Local)

判断Input是否以Test开头。Comp是比较字符的二元判断式。Local是std::local。

 

bool ends_with (Input, Test);

bool ends_with (Input, Test, Comp)

bool iends_with(Input, Test, Local)

判断Input是否以Test结尾。Comp是比较字符的二元判断式。Local是std::local。

 

bool contains (Input, Test);

bool contains (Input, Test, Comp)

bool icontains(Input, Test, Local)

判断Input是否包含Test。Comp是比较字符的二元判断式。Local是std::local。

 

bool equals (Input, Test);

bool equals (Input, Test, Comp)

bool iequals(Input, Test, Local)

判断Input是否和Test相同。Comp是比较字符的二元判断式。Local是std::local。

 

bool all(Input, Pred);

判断Input的每一个字符是否满足Pred判断式。

 

Classfication 类别判断式

classfication也是判断式,它们是对std::isspace等函数的泛型化封装。

unspecified is_classified(std::ctype_base::mask, const std::locale & = std::locale());

unspecified is_space      (const std::locale & = std::locale());

unspecified is_alnum      (const std::locale & = std::locale());

unspecified is_alpha      (const std::locale & = std::locale());

unspecified is_cntrl      (const std::locale & = std::locale());

unspecified is_digit      (const std::locale & = std::locale());

unspecified is_graph      (const std::locale & = std::locale());

unspecified is_lower      (const std::locale & = std::locale());

unspecified is_print      (const std::locale & = std::locale());

unspecified is_punct      (const std::locale & = std::locale());

unspecified is_upper      (const std::locale & = std::locale());

unspecified is_xdigit     (const std::locale & = std::locale());

判断字符是否是某个类型,返回判断式。

例:

trim_copy_if(string(“123Hello 890” , is_digit()));//return “Hello”

 

unspecified is_any_of(Set);

判断字符是否是Set中的一个,返回判断式。

 

unspecified is_from_range(From, To);

判断字符是否是否处在From和To之间(From<=Ch<=To)。

 

unspecified operator&&(Pred1, Pred2);

unspecified operator||(Pred1, Pred2);

unspecified operator!(Pred);

classfication判断式的与或非运算。注意:只能对上述的classfication判断式使用。

例:

trim_copy_if(string(“123Hello 890” ), is_digit()||is_upper());//return “ello”

 

iterator_range Class 迭代器范围类

iterator_range是对一组迭代器的封装。一般用于find算法的返回值。

iterator_range有类似于stl容器的begin(), end(), empty(), size(), swap(), bool operator()成员函数。

一般使用make_iterator_range()来构造iterator_rang,make_iterator_range使用两个迭代器或者是pair<iterator, iterator>作为参数。

还可以使用流来输出iterator_range。

例:

string str(“Hello”);

cout<<make_iterator_range(str.begin()+1, str.end()-1);//output “ell”

对于iterator_range的ostream输出类似于 copy(it.begin(),it.end(),ostream_iterator<char>(“”));

无空格的连续输出。

Erase Algorithm 删除算法

OutputIterator erase_range_copy (OutputIterator, Input, SearchRange);

Sequence       erase_range_copy (Input, SearchRange);

 

void           erase_range       (Input, SearchRange);

删除输入字符串中SearchRange那部分。SearchRange是一个iterator_range对象。

例:

std::string str1("Hello");

std::string str2;

    

boost::erase_range(str1, boost::make_iterator_range(str1.begin()+1, str1.end()-1));

cout<<str1<<endl;//输出”Ho”

 

erase_range_copy(back_inserter(str2),

                    str1,

                    boost::make_iterator_range(str1.begin()+1, str1.end()-1));

cout<<str2<<endl;//输出”Ho”

 

OutputIterator erase_first_copy(OutputIterator, Input, Search);

Sequence       erase_first_copy(Input, Search);

void           erase_first     (Input, Search);

 

OutputIterator ierase_first_copy(OutputIterator, Input, Search, Local);

Sequence       ierase_first_copy(Input, Search, Local);

void           ierase_first     (Input, Search, Local);

删除从Input中查找到的第一个Search。

例:

std::string str1("Hello");

std::string str2;

 

boost::erase_first(str1, "ll");

str2=boost::erase_first_copy(string("Hello"), "l");

cout<<str1<<endl;//输出”Heo”

cout<<str2<<endl;//输出”Helo”

 

OutputIterator erase_last_copy(OutputIterator, Input, Search);

Sequence       erase_last_copy(Input, Search);

void           erase_last     (Input, Search);

 

OutputIterator ierase_last_copy(OutputIterator, Input, Search, Local);

Sequence       ierase_last_copy(Input, Search, Local);

void           ierase_last     (Input, Search, Local);

删除从Input中查找到的最后一个Search。

 

OutputIterator erase_nth_copy(OutputIterator, Input, Search, n);

Sequence       erase_nth_copy(Input, Search, n);

void           erase_nth      (Input, Search, n);

 

OutputIterator ierase_nth_copy(OutputIterator, Input, Search, n, Local);

Sequence       ierase_nth_copy(Input, Search, n, Local);

void           ierase_nth     (Input, Search, n, Local);

删除从Input中查找到的第n个Search。(n是基于0的)

 

OutputIterator erase_all_copy(OutputIterator, Input, Search);

Sequence       erase_all_copy(Input, Search);

void           erase_all     (Input, Search);

 

OutputIterator ierase_all_copy(OutputIterator, Input, Search, Local);

Sequence       ierase_all_copy(Input, Search, Local);

void           ierase_all     (Input, Search, Local);

删除从Input中查找到的所有Search。

 

OutputIterator erase_head_copy (OutputIterator, Input, n);

Sequence       erase_head_copy (Input, n);

void           erase_head     (Input, n)

删除Input的前n个字符。如果n大于输入字符串长度,那么整个字符串会被删除。

 

OutputIterator erase_tail_copy (OutputIterator, Input, n);

Sequence       erase_tail_copy (Input, n);

void           erase_tail      (Input, n);

删除Input的最后n个字符。如果n大于输入字符串长度,那么整个字符串会被删除。

 

Replace Algorithm 替换算法

OutputIterator replace_range_copy (OutputIterator, Input, SearchRange, Format);

Sequence       replace_range_copy (Input, SearchRange, Format);

void           replace_range      (Input, SearchRange, Format);

把Input中的SearchRange部分替换成Format。

 

OutputIterator replace_first_copy (OutputIterator, Input, Search, Format);

Sequence       replace_first_copy (Input, Search, Format);

void           replace_first      (Input, Search, Format);

 

OutputIterator ireplace_first_copy (OutputIterator, Input, Search, Format, Local);

Sequence       ireplace_first_copy (Input, Search, Format, Local);

void           ireplace_first      (Input, Search, Format, Local);

把Input中搜索到的第一个Search替换成Format。

 

OutputIterator replace_last_copy (OutputIterator, Input, Search, Format);

Sequence       replace_last_copy (Input, Search, Format);

void           replace_last      (Input, Search, Format);

 

OutputIterator ireplace_last_copy (OutputIterator, Input, Search, Format, Local);

Sequence       ireplace_last_copy (Input, Search, Format, Local);

void           ireplace_last      (Input, Search, Format, Local);

把Input中搜索到的最后一个Search替换成Format。

 

OutputIterator replace_nth_copy (OutputIterator, Input, Search, Format, n);

Sequence       replace_nth_copy (Input, Search, Format, n);

void           replace_nth      (Input, Search, Format, n);

 

OutputIterator ireplace_nth_copy (OutputIterator, Input, Search, Format, n, Local);

Sequence       ireplace_nth_copy (Input, Search, Format, n, Local);

void           ireplace_nth      (Input, Search, Format, n, Local);

把Input中搜索到的第n个Search替换成Format。

 

OutputIterator replace_all_copy (OutputIterator, Input, Search, Format);

Sequence       replace_all_copy (Input, Search, Format);

void           replace_all      (Input, Search, Format);

 

OutputIterator ireplace_all_copy (OutputIterator, Input, Search, Format, Local);

Sequence       ireplace_all_copy (Input, Search, Format, Local);

void           ireplace_all      (Input, Search, Format, Local);

把Input中所有的Search替换成Format。

 

OutputIterator replace_head_copy(OutputIterator, Input, n, Format);

Sequence       replace_head_copy(Input, n, Format);

void           replace_head     (Input, n, Format);

把Input中前n个字符替换成Format。

 

OutputIterator replace_tail_copy(OutputIterator, Input, n, Format);

Sequence        replace_tail_copy(Input, n, Format);

void             replace_tail      (Input, n, Format);

把Input中最后n个字符替换成Format。

 

Finder Object Finder仿函数

Finder Object是一个仿函数,它用来决定在find算法中的匹配策略。可以在find_iterator中使用。

Finder first_finder(Search);

Finder first_finder(Search, Comp);

返回在输入中查找第一个Search的Finder对象。

 

Finder last_finder(Search);

Finder last_finder(Search, Comp);

返回在输入中查找最后一个Search的Finder对象。

 

Finder nth_finder(Search, n);

Finder nth_finder(Search, n, Comp);

返回在输入中查找第一个Search的Finder对象。

 

Finder head_finder(n);

Finder tail_finder(n);

返回在输入中查找最前(后)n个字符的Finder对象。(n是基于0的)

 

Finder token_finder(Pred, Compress= token_compress_off);

返回满足Pred判断式的字符的查找的Finder对象。

Pred 是类似于bool pred(char c);这样的函数或仿函数。

Compress可以取值为:

token_compress_on :将相邻的满足Pred的字符合并作为查找结果。

token_compress_off:不合并相邻的字符。

例如:对于bind2nd(equal_to<char>,’c’)这样的判断式,用token_finder查找”aabbcc”,对于token_compress_on结果是”cc”,对于token_compress_off是分别查找到两个”c”。

 

Finder range_finder(beg, end);

Finder range_finder(iterator_range);

返回查找特定范围的Finder对象。

Find算法

Find算法是在字符串中查找子串的算法,算法返回iterator_range类型。

iterator_range find(Input, Finder);

iterator_range find_first(Input, Search);

iterator_range ifind_first(Input, Search,Local=std::local());

iterator_range find_last(Input, Search);

iterator_range ifind_last(Input, Search, Local=std::local());

iterator_range find_nth(Input, Search, n);

iterator_range ifind_nth(Input, Search, n, Local=std::local());

iterator_range find_head(Input, n);

iterator_range find_tail(Input, n);

iterator_range find_token(Input, Pred, Compress= token_compress_off);

上述的算法都很简单,我就不多说了。

我来分析一下find_first,find_first的源代码是这样的:

template<typename Collection1T, typename Collection2T>

        inline iterator_range<

            BOOST_STRING_TYPENAME result_iterator_of<Collection1T>::type>

        find_first(

            Collection1T& Input,

            const Collection2T& Search)

        {

            return first_finder(Search)(

                begin(Input),end(Input));

        }

result_iterator_of<Collection1T>::type是Collection1T::iterator

begin(Input)是Input.begin()

end(Input)是Input.end()

first_finder(Search)返回一个first_finder对象,然后调用这个Finder.operator()(beg,end),并且以iterator_range作为查找结果返回。其实对于每一个Finder都重载了operator()函数,使用这个函数就可以对字符串直接查找。

 

Find Iterator 查找迭代器

find算法只能查找到一个结果,而通过find_iterator可以查找所有的结果。

template<typename Iterator> class find_iterator;

find_iterator make_find_iterator(Input, Finder);

find_iterator的成员函数:

  find_iterator()默认构造函数

  find_iterator(beg, end, Finder)在beg和end之间查找

  find_iterator(Input, Finder)查找Input

 

  bool eof()是否查找结束

例:

std::string str1("ten 10 nine 9 and eight 8");

 

boost::find_iterator<string::iterator> it;

for (it = make_find_iterator(str1,

                                  token_finder(boost::is_digit(),

                                                 boost::token_compress_on)//查找连续数字的token_finder

                                 )

         ;!it.eof();++it)//注意是it.eof(),it->意味着(*it). 而*it是一个iterator_range对象

        cout<<*it<<endl;//*it返回查找结果:一个iterator_range对象,而一个iterator_range是可以直接输出的。

//输出:

//10

//9

//8

 

在使用find_iterator的过程中,不能修改字符串的长度,例如:erase_range(str1,*it)如果是replace就可以。

另外,find_iterator是Forward迭代器,不能--it。

 

template<typename Iterator> class split_iterator;

find_iterator make_split_iterator(Input, Finder);

split_iterator使用查找到的字串来分隔字符串,例如对于上述例子,用split替换find,结果是:

ten

 nine

 and eight

 

splite_iterator的其它用法和find_iterator一样。

boost::iterator_range用法详解 总结一下,boost::iterator_range是Boost库中一个非常实用的工具,它简化了迭代器范围的处理和操作。boost::iterator_range的一个重要特性是它的灵活性。接下来,我们使用boost::iterator_range创建了一个迭代器范围对象range,它的起始迭代器是numbers.begin(),结束迭代器是numbers.end()。boost::iterator_range的使用非常简单,我们只需要提供起始迭代器和结束迭代器,它将自动构建一个迭代器范围对象。 阅读详情

相关推荐

boost::iterator_range的使用示例

上面的代码中,我们用boost::make_iterator_range函数将vector容器的迭代器范围封装成一个iterator_range对象,并在for循环中遍历其中的元素。需要注意的是,iterator_range并不会拥有封装的迭代器,也就是说,它并不会负责管理迭代器的生命周期。它有两个模板参数,一个是起始迭代器类型,另一个是终止迭代器类型。上面的代码中,我们将一个整型数组a的指针范围封装成了一个iterator_range对象,并在for循环中遍历其中的元素。

Book_Sea的博客 212

Learning boost 3 -- string algorithm 1

Learning boost 3string algorithm 1简介string algorithm是boost中提供字符串算法的类库。在这里,字符串不一定是std::basic_string,也可以是其它的stl容器或是c++中的零结尾字符串char*。例:std::string str("Hello");std::vector vstr(str.begin(),

heroboy2000的专栏 8918

String Algorithm

Stanford University CS97SI Slides. The String Algorithm Slides.

c语言range用法,boost库区间range基本原理及使用实例

区间的概念类似于STL中的容器概念。一个区间提供了可以访问半开放区间[first,one_past_last)中元素的迭代器,还提供了区间中的元素数量的信息。引入区间概念的目的在于:有很多类似于容器的类型,以及用于这些类型的简化算法。实例代码:void test_range_construct_string(){typedef std::string::iterator iterator;ty...

weixin_35588980的博客 1193

金融风控实战:用Python从零搭建贷款违约预测模型(附完整数据集)

本文详细介绍了如何使用Python从零构建金融风控中的贷款违约预测模型,涵盖数据清洗、特征工程、模型构建与评估等全流程。通过实战案例展示逻辑回归、XGBoost和LightGBM三大算法的对比,特别强调AUC-ROC指标在金融风控中的重要性,并附完整数据集和代码实现。

weixin_29175469的博客 237

PX4开发环境搭建(Ubuntu1804+QGC+Qt Creator )

文章目录前言一、安装环境二、PX4环境搭建1. 在虚拟机中安装Ubuntu2. 安装PX4环境(1)下载PX4源码:(2) 安装工具链(3) jMAVSim仿真(4) 编译验证三、安装QGC四、安装Qt Creator 前言 在这之前作者完全没接触过PX4,安装过程遇到了很多坑,而且每安装下载一个东西都要等好久,出现问题又要重新开始,前后折腾了四天才弄好,希望此文对大家有所帮助。 一、安装环境 ...

Beyonderwei的博客 9021

String Algorithm Summary - 1

目录 Suffix Array Summay 单个字符串问题 两个字符串问题 多个字符串问题 AC-Automaton Summary 求长度为n(2e9)不包含给定字符串的合法串个数 包含至少一个词根长度不超过n(2e9...

weixin_30404405的博客 133

免费升级哨兵2号分辨率!用SRCNN深度学习模型实现10米→2.5米超分重建

本文详细介绍了如何利用SRCNN深度学习模型,将哨兵2号遥感影像的分辨率从10米免费提升至2.5米。文章提供了从数据准备、模型训练到部署应用的全流程实战指南,旨在通过AI应用技术,为农业监测、城市规划等领域提供更高精度的影像数据支持。

coffee的博客 523

Algorithm: String (1) 特殊的题目

6. ZigZag Conversion 68. Text Justification 71. Simplify Path 214. Shortest Palindrome String Comparison String Compression 6. ZigZag Conversion The string "PAYPALISHIRING" is w

Steven Li's Zone 587

R语言生存分析之限制性立方样条分析:样条回归、和多项式回归有什么不同?是否存在非线性关系、限制性立方样条cox回归模型

R语言生存分析之限制性立方样条分析:样条回归、和多项式回归有什么不同?是否存在非线性关系、限制性立方样条cox回归模型

statistics+insight+vista+power 634

RK+linux教程:RK3588 RGA硬件加速在YOLOv5图像预处理中的深度应用教程

摘要: 本教程深入解析了RK3588芯片的RGA硬件加速器在YOLOv5图像预处理中的应用。通过专用硬件设计,RGA支持图像缩放、边界填充等核心操作,结合零拷贝技术显著提升处理效率。重点分析了LetterBox算法的RGA实现,包括参数计算、边界填充和性能优化,并与传统CPU处理对比,展示了RGA在高分辨率图像处理中的优势。教程还提供了统一的预处理接口设计,便于在OpenCV与RGA方案间灵活切换,为RK3588平台的深度学习部署提供实用优化方案。

LXY_LOVE36的博客 975

1.1 Implement an algorithm to determine if a string has all unique characters.

Implement an algorithm to determine if a string has all unique characters.What if you can not use additional data structures? 思路:首先,字符串是ascii编码还是unicode编码,这会影响记录的数组。  用bool ch[256] 记录所有的字符,初始化为fa

xinxinxv的专栏 720

SAP-ABAP:SAP数据库视图的创建图文详解

在“短文本”字段中输入视图的描述。在“表/视图”字段中输入要基于的表名。如果视图基于多个表,可以在这里输入主表。点击“表/视图字段”按钮,选择要包含在视图中的字段。如果视图基于多个表,点击“关系”按钮来定义表之间的连接条件。在弹出的窗口中,选择要连接的表,并定义连接条件(例如。

baidu_35680696的博客 973

LeetCode 686. Repeated String Match, 1. Rabin Karp's algorithm with Rolling Hash, 2. Brute Search

问题描述 给定两个字符串 A 和 B, 寻找重复叠加字符串A的最小次数,使得字符串B成为叠加后的字符串A的子串,如果不存在则返回 -1。 举个例子,A = “abcd”,B = “cdabcdab”。 答案为 3, 因为 A 重复叠加三遍后为 “abcdabcdabcd”,此时 B 是其子串;A 重复叠加两遍后为"abcdabcd",B 并不是其子串。 注意: A 与 B 字符串的长度在1和1...

weixin_42919606的博客 318

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us...

思路: 假设给定字符串用的是ASCII编码,那么总共就只有256个字符,新建一个256个元素的boolean数组, 遍历字符串,将出现的字符在boolean数组所在位置置 1。如果碰到已经置一,表明出现重复字符,返回false。 public class IsUniqueChars_1 { public boolean solu(String s) { b...

weixin_30462049的博客 166

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

c++内置函数实现字符串翻转(reverse,strrev,string 构造函数)

c++内置函数实现字符串翻转(reverse,strrev,string 构造函数) 在写程序的时候,我们经常需要将字符串进行翻转。c++中内置的函数有不少个可以实现该功能。 1.strrev函数。(cstring) #include <iostream> #include <cstring> using namespace std; int main() { string s="abcd"; strrev(s); cout<<s&lt

u014339447的博客 4万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

ZOJ1383 Binary Numbers

#include<string> #include<iostream> #include<bitset> #include<algorithm> using namespace std; int main(){ int T, n; cin>>T; while(T--){ cin>>n; string s = ...

姚军 324

C++ 常用算法补注

【代码】C++ 常用算法补注。

嵌入式点灯砖家的博客 115

字符串反转的3种方法

1.自己编写 #include &lt;iostream&gt; using namespace std;   void Reverse(char *s,int n){     for(int i=0,j=n-1;i&lt;j;i++,j--){         char c=s[i];         s[i]=s[j];         s[j]=c;     } }   int main...

哆啦A梦~~ 1293

String类的subString(i)方法(基于jdk 1.9)

只有一个参数的; String str = new String("ABCD"); System.out.println("str="+str.substring(1)); 进入substring() public String substring(int beginIndex) { if (beginIndex < 0) { throw new S...

weixin_34138056的博客 900

UVa1225

#pragma warning(disable:4996) #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<algorithm> #include<iostream> #include<time.h> #include<set> #include<sstream

JACK_JYH的博客 455

Leetcode 344. Reverse String

【代码】Leetcode 344. Reverse String。

小白菜又菜 393
上一篇: Tuple and ref
下一篇: Smart ptr
chalichen
博客等级 码龄22年 0粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值