去掉重复之后还剩几个
运行下面这段程序:
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#include <unordered_map>
int main() {
vector<string> words = {"苹果", "香蕉", "苹果", "梨", "香蕉", "苹果"};
unordered_map<string, bool> seen;
for (const string& w : words) seen[w] = true;
cout << seen.size() << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)
全部评论