当前位置: 首页 > wzjs >正文

天津seo推广方法青岛seo建站

天津seo推广方法,青岛seo建站,wordpress 配置邮件,雨人网站建设目录 1. 练习2.1题目答案 2. 练习2.2题目答案 3. 练习2.3题目答案 参考 1. 练习2.1 题目 编写一个程序,要求用户输入两个字符串,然后使用三向比较运算符将其按字母表顺序打印出来。为了获取一个字符串,可以使用std::cin流。 std::string s;…

目录

  • 1. 练习2.1
    • 题目
    • 答案
  • 2. 练习2.2
    • 题目
    • 答案
  • 3. 练习2.3
    • 题目
    • 答案
  • 参考

1. 练习2.1

题目

  编写一个程序,要求用户输入两个字符串,然后使用三向比较运算符将其按字母表顺序打印出来。为了获取一个字符串,可以使用std::cin流。

std::string s;
std::getline(std::cin, s);

答案

int main() {std::string s1, s2;std::cout << "input String1: ";std::getline(std::cin, s1);std::cout << "input String2: ";std::getline(std::cin, s2);std::strong_ordering result = s1 <=> s2;if (std::is_lt(result)) {std::cout << std::format("{}\n{}\n", s1, s2);}else if (std::is_gt(result)) {std::cout << std::format("{}\n{}\n", s2, s1);}else {std::cout << std::format("{}\n{}\n", s1, s2);}
}

2. 练习2.2

题目

  编写一个程序,要求用户提供源字符串haystack、要在源字符串中查找的字符串needle以及替换字符串。编写一个包含3个参数的函数:haystack、needle和replacement_string,该函数返回一个haystack的副本,其中所有的needle都被替换成replacement_string.要求使用std::string,不使用std::string。你将使用哪种类型的参数,为什么?在main()中调用此函数并打印所有字符串以进行验证。

答案

static std::string replaceAllSubString(const std::string& haystack,const std::string& needle,const std::string& replacement_string) {std::string newstr { haystack };size_t pos { newstr.find(needle) };while (pos != std::string::npos) {newstr = newstr.erase(pos, needle.size());newstr = newstr.insert(pos, replacement_string);pos = newstr.find(needle, pos + replacement_string.size());}return newstr;
}int main() {std::string s { "ababbbbbaaababababababababbaaaaa" };std::string olds { "ab" };std::string news { "aba" };std::cout << replaceAllSubString(s, olds, news) << std::endl;
}

3. 练习2.3

题目

  修改练习2.2中的程序,并尽可能多地使用std::string_view。

答案

static std::string replaceAllSubString(std::string_view haystack,std::string_view needle,std::string_view replacement_string) {std::string newstr { haystack };size_t pos { newstr.find(needle) };while (pos != std::string::npos) {newstr = newstr.erase(pos, needle.size());newstr = newstr.insert(pos, replacement_string);pos = newstr.find(needle, pos + replacement_string.size());}return newstr;
}int main() {std::string_view s { "ababbbbbaaababababababababbaaaaa" };std::string_view olds { "ab" };std::string_view news { "aba" };std::cout << replaceAllSubString(s, olds, news) << std::endl;
}

参考

[比] 马克·格雷戈勒著 程序喵大人 惠惠 墨梵 译 C++20高级编程(第五版)

http://www.dtcms.com/wzjs/145173.html

相关文章:

  • 不会网站维护可以做吗a5站长网网站交易
  • 有没有做生物科技相关的网站公司网络推广的作用
  • 网站平台怎么做的提高网站流量的软文案例
  • 熊掌号怎么域名做网站请你设计一个网络营销方案
  • 怎么设计手机网站百度网站域名注册
  • 如何知道一个网站是谁做的关键词排名怎么查
  • 做剧情网站侵权吗免费p站推广网站入口
  • txt发布wordpress关键词优化的方法有哪些
  • 网站关键词优化排名要怎么做百度小说网
  • 门户网站系统建设方案seo自学网官方
  • 淘客手机网站模板安徽企业网站建设
  • 政府门户网站制度建设情况小红书seo排名帝搜软件
  • 点击网站出现微信二维码的链接怎么做手机端seo
  • 网站首页一般做多大尺寸认识网络营销
  • 南宁网站开发企业成都搜索优化排名公司
  • 平面设计制作郑州优化公司有哪些
  • 锦州网站建设公司广告投放平台排名
  • 德州极速网站建设北京seo营销培训
  • 做音响网站网站优化排名服务
  • 建设厅网站账户名忘了怎么查淘宝指数查询工具
  • 网站维护内容百度广告代理商加盟
  • 邹平做网站公司搜索引擎排名中国
  • 网站专题二级页怎么做建站教程
  • 平面广告设计要用什么软件有哪些关键词seo如何优化
  • 建网360 网站建设最优化方法
  • wordpress 混合移动app网站优化有哪些技巧
  • 嘉兴做网站seo百度怎么推广自己的网站
  • 网站防注入nba湖人队最新消息
  • 广安哪里做网站国家免费技能培训有哪些
  • 网站制作成都长春网站快速优化排名