2019独角兽企业重金招聘Python工程师标准>>>

#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
string line1="We were her pride of 10 she named us:";string line2="benjamin,phoenix,the prodigal";
string line3="and perspicacious pacific Suzanne";string sentence=line1+' '+line2+' '+line3;
string separators(" \t:,\v\r\n\f");
string word;
string::size_type maxlen,minlen,wordlen,count=0;
vector<string> longestWords,shortestWords;
string::size_type startPos=0,endPos=0;
while((startPos=sentence.find_first_not_of(separators,endPos))!=string::npos)
{++count;endPos=sentence.find_first_of(separators,startPos);if(endPos==string::npos){wordlen=sentence.size()-startPos;}else{wordlen=endPos-startPos;}word.assign(sentence.begin()+startPos,sentence.begin()+startPos+wordlen);startPos=sentence.find_first_not_of(separators,endPos);if(count==1){ maxlen=minlen=wordlen;longestWords.push_back(word);shortestWords.push_back(word);}else{if(wordlen>maxlen){maxlen=wordlen;longestWords.clear();longestWords.push_back(word);}else if(wordlen==maxlen)longestWords.push_back(word);if(wordlen<minlen){minlen=wordlen;shortestWords.clear();shortestWords.push_back(word);}else if(wordlen==minlen)shortestWords.push_back(word);}
}cout<<"word amount "<<count<<endl;vector<string>::iterator iter;cout<<"longest word(s):"<<endl;iter=longestWords.begin();while(iter!=longestWords.end())cout<<*iter++<<endl;cout<<"shortest word(s):"<<endl;iter=shortestWords.begin();while(iter!=shortestWords.end())cout<<*iter++<<endl;return 0;}

转载于:https://my.oschina.net/lizming/blog/209933

c++primer 容器算法整理一相关推荐

  1. c++ 特定容器算法(sort,merge,reverse,remove,unique)

    下面内容都是特定容器算法,也就是c++,list和forward_list特有的算法. 第一部分:成员函数算法merge(forward_list和list专用) 1.c++ primer 5th p ...

  2. 【Qt】通过QtCreator源码学习Qt(九):容器算法总结

    一.简介 本节总结QtCreator中封装的容器算法接口,源码文件的路径src/libs/utils/algorithm.h. 算法接口包括:判断.查找.删除.统计.排序.转换.拆分.过滤 二.算法源 ...

  3. 最短路径算法整理(二)

    本文是最短路径算法整理的第二篇,想阅读第一篇的朋友能够点击下面链接: http://blog.csdn.net/hjd_love_zzt/article/details/26739593 这一篇博客继 ...

  4. 常见数据结构与算法整理总结(下)

    原文链接:https://www.jianshu.com/p/42f81846c0fb 这篇文章是常见数据结构与算法整理总结的下篇,上一篇主要是对常见的数据结构进行集中总结,这篇主要是总结一些常见的算 ...

  5. C++实验课任务(多态--容器--算法)

    C++实验课任务(多态–容器–算法) 题目的基本实现 代码如下(具体细节处的分析见代码中/**/里的部分): #pragma once #include <string> #include ...

  6. 最短路算法整理 七七八八的总结

    最短路算法整理 1.Dijkstra 算法 先讲讲朴素的Dijkstra算法的思路.朴素的Dijkstra算法先将起点入队.然后找到一个起点距离最近的点.再用这个点去更新其他所有的点.一共有多少个点就 ...

  7. SM4国密算法整理-流程图

    SM4国密算法整理–流程图 前一篇文章没有加入流程图,自己看着也有点晕,现在再次整理下 python代码看我之前的文章: 请点击. 加密 计算轮秘钥 #mermaid-svg-LmTcVIQC7cAr ...

  8. 精华游戏算法整理_整理游戏

    精华游戏算法整理 在HTML5 2D游戏开发系列的上一部分文章结尾,Snail Bait处于可玩但原始的状态. 在这一期的最后一部分中,我将向您展示如何将Snail Bait从该状态带到最终版本,如图 ...

  9. 百度算法整理,SEO工作者抓紧收藏了!(超详细)

    入行SEO这么长时间,要避免踩到百度算法的雷区就得经常查百度算法.而一个一个地去找算法就比较麻烦,于是我按照功能对应的算法整理了2013年以来的百度算法供大家参考(截止到2019年). 一.网站质量相 ...

  10. Terrain 算法整理。基本常识。

    Terrain 算法整理.基本常识. 制作地形的方法大致分为 Voxel, Height map, Mesh 这几种,会根据使用的技术有各自的长短处,常识上的长短处如下.Unity 用的是高度图,所以 ...

最新文章

  1. c语言logout_C++ 格式化日志输出实现代码
  2. 高薪源于专注和极致!
  3. 【Matlab 图像】 app designer
  4. Ubuntu18.04 unzip解压zip文件乱码的解决方法
  5. VTK:图片之ImageSlice
  6. python错误怎么处理_python报的错误怎么处理
  7. P3358 最长k可重区间集问题(网络流:串联思想)
  8. Android 隐藏状态栏,沉浸式状态栏,状态栏背景色,状态栏字体色,透明状态工具类
  9. 匈牙利算法——最大匹配问题详解
  10. Intel 64/x86_64/IA-32/x86处理器 - 通用指令(7) - 标志寄存器/标志控制指令 段寄存器指令
  11. Redis深入浅出----演讲
  12. Dynamics Ax 2012中调用外部web服务
  13. oracle表转换mysql建表语句
  14. 《买土豆的故事》——经典职场故事
  15. Excel一键求得单元格内数值个数的操作!
  16. dreamweaver html css,Dreamweaver CC
  17. Malloc源码解读三——Bins与Arena
  18. python什么意思g_在laymans术语中,Python字符串格式“g”实际上是什么意思?
  19. 标准std::string分割字符串split
  20. HTML5中Audio对象volume属性的应用

热门文章

  1. paip.分成系统会员推广分销系统的设计
  2. Toml :设置策略配置文件
  3. Julia: 关于Array排序函数sortslices
  4. 如何在云上高效地实践“自动化”和“弹性”
  5. HR,是该做一个Excel仪表盘了!
  6. 开源实战 | 手把手教你在 Azure 上畅享 SAP、SUSE全套解决方案
  7. 如何写出优秀的开源简历
  8. 【数学建模】基于matlab模拟十字路口车辆通行【含Matlab源码 1106期】
  9. 您实际上可以通过这些YouTube视频了解GPT-3
  10. 智能家居系统c语言源代码,智能家居软件设计(附源程序).doc