本人初学计算机C++语言,练习vector,需要用到sort函数,但是电脑中没有这个函数,请问如何编写sort函数?
C++中如何编写sort函数
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 小公鸡卡哇伊呀~ 2021-10-06 23:43关注
又试了一下,windows Ctrl + Z 是可以终止输入的:
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main() { vector<string> words; for (string temp; cin >> temp;) words.push_back(temp); cout << words.size() << endl; sort(words.begin(), words.end()); for (size_t i = 0; i < words.size(); i++) cout << words[i] << " "; // 删除重复的单词 words.erase(unique(words.begin(), words.end()), words.end()); cout << endl; cout << words.size() << endl; for (size_t i = 0; i < words.size(); i++) cout << words[i] << " "; return 0; }
测试如下:
this is my vector you know my vector ^Z 8 is know my my this vector vector you 6 is know my this vector you 请按任意键继续. . .
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 springboot 3.0 实现Security 6.x版本集成
- ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
- ¥15 请帮我解决一下下面六个代码
- ¥15 关于资源监视工具的e-care有知道的嘛
- ¥35 MIMO天线稀疏阵列排布问题
- ¥60 用visual studio编写程序,利用间接平差求解水准网
- ¥15 Llama如何调用shell或者Python
- ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
- ¥15 win10权限管理,限制普通用户使用删除功能
- ¥15 minnio内存占用过大,内存没被回收(Windows环境)