您的位置:首页 > 编程语言 > C语言/C++

C++,输入一组数字,并对其升序排序,删除指定范围内的元素

2013-10-26 15:38 453 查看
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
string inputString;
vector<string> sVec;
cout<<"Please input the input string :";
while (cin>>inputString) {
sVec.push_back(inputString);
}

cout<<"The input string is : ";
vector<string>::const_iterator firstIter = sVec.begin();
for (firstIter; firstIter != sVec.end(); ++firstIter) {
cout<<*firstIter<<ends;
}
cout<<endl;

cin.clear();

//升序排序
sort(sVec.begin(),sVec.end());
cout<<"The after sort is ";
vector<string>::const_iterator firstIter = sVec.begin();
for (firstIter; firstIter != sVec.end(); ++firstIter) {
cout<<*firstIter<<ends;
}
cout<<endl;

cout<<"Please input the erease value:";
string s1,s2;
cin>>s1>>s2;

vector<string>::iterator sIter = sVec.begin();
vector<string>::iterator sIterEnd = sVec.end();
vector<string>::iterator findIter,findIter2;
findIter   = find(sIter,sIterEnd,s1);
findIter2  = find(sIter,sIterEnd,s2);
if ((findIter != sIterEnd) && (findIter2 != sIterEnd)) {
sVec.erase(findIter,findIter2);
}

cout<<"The output string is : ";
vector<string>::const_iterator firstIter = sVec.begin();
for (firstIter; firstIter != sVec.end(); ++firstIter) {
cout<<*firstIter<<ends;
}

cout<<endl;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐