顺序容器的使用C++
来源:互联网 发布:删除数据库用户 编辑:程序博客网 时间:2024/06/11 15:07
有关顺序容器的使用,觉得可以拿出来,值得拿出来的东西,写起来也不是那么简单.
刚刚去软考报名回来,软件设计师,又要开始了.一次小小的旅行,美丽的世界,等着我吧.
贴咯,不多说.
// 9-39-2011-09-03-10.09.cpp -- 第九章第三十九题#include "stdafx.h"#include <iostream>#include <string>#include <vector>using namespace std ;const unsigned int Infinity = 1 << 31 ;void processStringAndPrintStatisticResult (const string & str, const string & separators) ;int _tmain(int argc, _TCHAR* argv[]){string separators(",:\v\r\t\n?!. ") ;string line1 = "We were her pride of 10 she names us:" ;string line2 = "Benjamin, Phoenix, the Prodigal" ;string line3 = "and perspicacious pacific Suzanne" ;string sentence = line1 + ' ' + line2 + ' ' + line3 ;processStringAndPrintStatisticResult(sentence, separators) ;return 0 ;}void processStringAndPrintStatisticResult (const string & str, const string & separators){string ::size_type numOfWords = 0 ;vector<string> longestWords ;vector<string> shortestWords ;string ::size_type maxLength = 0 ;string ::size_type minLength = Infinity ;string ::size_type letterStartPos = 0 ;string ::size_type separatorStartPos = 0 ;string word ;while ((letterStartPos = str.find_first_not_of(separators, letterStartPos)) != string ::npos){separatorStartPos = str.find_first_of(separators, letterStartPos) ;//Calculate length of word.++numOfWords ;//Extract the word has been found just now.if (separatorStartPos != string ::npos){word.assign(str.begin() + letterStartPos, str.begin() + separatorStartPos) ;}else{word.assign(str.begin() + letterStartPos, str.end()) ;}if (word.size() > maxLength){maxLength = word.size() ;longestWords.clear() ;longestWords.push_back(word) ;}else if (word.size() == maxLength){longestWords.push_back(word) ;}if (word.size() < minLength){minLength = word.size() ;shortestWords.clear() ;shortestWords.push_back(word) ;}else if (word.size() == minLength){shortestWords.push_back(word) ;}//Updata letterStartPos.letterStartPos = separatorStartPos ;}cout << "Number of words is : " << numOfWords << endl ;cout << "All maximum length words:" << endl ;vector<string> ::const_iterator iter = longestWords.begin() ;while (iter != longestWords.end()){cout << *iter << endl ;++iter ;}cout << "All minimum length words:" << endl ;iter = shortestWords.begin() ;while (iter != shortestWords.end()){cout << *iter << endl ;++iter ;}}
- 顺序容器的使用
- 小结顺序容器的使用
- 小结顺序容器的使用
- 小结顺序容器的使用
- 顺序容器的使用C++
- C ++ 读书笔记 顺序容器
- 《C++primer》 顺序容器
- C++Primer 顺序容器
- C++---顺序容器
- 【c++】stl顺序容器
- C++容器-2顺序容器vector、list、deque的使用
- 顺序容器:顺序容器的操作
- 【C++】顺序容器 Vector 注意事项
- C++:顺序容器与迭代器
- C++primer【笔记】 顺序容器
- C++——STL中三种顺序容器的简要区别
- 本科教育忽略的黄金C++<2> 顺序容器
- 【day0412 C++】顺序容器 STL list类的应用
- Android: Downloading the Google USB Driver
- No 77 · 以油画效果显示图像
- delphi base64编码函数EncodeString的问题
- No 78 · 以扭曲效果显示图像
- No 79 · 以分块效果显示图像
- 顺序容器的使用C++
- Myeclipse去掉对JS等文件的验证
- No 80 · 以四周扩散方式显示图像
- No 81 · 以从上向下拉伸方式显示图像
- 文件系统的缺陷----导致数据库系统--同时也是数据库中需要避免的
- TeX系列: tikz & pgf 宏包安装步骤
- No 82 · 以从左向右拉伸方式显示图像
- LVM操作转载
- 单源最短路径BellmanFord算法头文件C++