C++编写程序对12个月的英文单词根据字典序进行从小到大的排序,请使用string向量实现。
展开全部
#include <iostream>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
vector<string> stringList;
vector<string>::iterator num;
const string month[12]={"january","february","march","april","may","june","july","august","september","october","november","december"};
for(int i=0;i<12;i++){
stringList.push_back(month[i]);
}
cout<<"排序前:"<<endl;
for(num=stringList.begin();num!=stringList.end();num++){
cout<<*num<<" ";
}
cout<<endl;
sort(stringList.begin(), stringList.end());
cout<<"排序后:"<<endl;
for(num=stringList.begin();num!=stringList.end();num++){
cout<<*num<<" ";
}
system("PAUSE");
return EXIT_SUCCESS;
}
已实现,如果哪里不懂可以问我。
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
vector<string> stringList;
vector<string>::iterator num;
const string month[12]={"january","february","march","april","may","june","july","august","september","october","november","december"};
for(int i=0;i<12;i++){
stringList.push_back(month[i]);
}
cout<<"排序前:"<<endl;
for(num=stringList.begin();num!=stringList.end();num++){
cout<<*num<<" ";
}
cout<<endl;
sort(stringList.begin(), stringList.end());
cout<<"排序后:"<<endl;
for(num=stringList.begin();num!=stringList.end();num++){
cout<<*num<<" ";
}
system("PAUSE");
return EXIT_SUCCESS;
}
已实现,如果哪里不懂可以问我。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询