C++在矢量中查找重复符号的问题,可以通过以下步骤解决:
#include <iostream>
#include <vector>
#include <unordered_set>
int main() {
std::vector<char> symbols = {'a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'};
std::unordered_set<char> seen_symbols;
for (const auto& symbol : symbols) {
if (seen_symbols.find(symbol) != seen_symbols.end()) {
std::cout << "重复符号:" << symbol << std::endl;
} else {
seen_symbols.insert(symbol);
}
}
return 0;
}
领取专属 10元无门槛券
手把手带您无忧上云