⚠️ 去重和排序,是躲不掉的

👁️ 1 人浏览 💬 0 人评论 ❤️ 添加收藏

(本条路线统一用 g++ -std=c++17 -O0 -Wall 编译)

#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

int main() {
    /* map / set 遍历一定是按键排序的;vector 是你放进去的顺序 */
    std::vector<std::string> v{"pear", "apple", "fig"};
    std::set<std::string> s{"pear", "apple", "fig"};

    std::string vfirst = v.front();
    std::string sfirst = *s.begin();

    /* set 会去重,vector 不会 */
    std::vector<int> vi{3, 1, 3};
    std::set<int> si{3, 1, 3};

    std::cout << vfirst << "/" << sfirst << "/"
              << vi.size() << "/" << si.size() << "\n";
    return 0;
}
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论