gpt4 book ai didi

c++ - 如何查找数组中是否有重复元素? C++

转载 作者:行者123 更新时间:2023-11-27 23:42:17 30 4
gpt4 key购买 nike

我正在尝试阅读我拥有的 50.000 个单词的单词列表,并整理出所有带有重复字母的单词。我已经成功地选择了一个随机单词,将其转换为数组中的字符,但我如何在该数组中搜索重复项?

最佳答案

std::adjacent_find是你的 friend :

template< class ForwardIt >
ForwardIt adjacent_find( ForwardIt first, ForwardIt last );

Searches the range [first, last) for two consecutive identical elements.

Return value

an iterator to the first of the first pair of identical elements [...] If no such elements are found, last is returned

首先对数组进行排序,然后对其执行adjacent_find 并检查它是否最后返回。

关于c++ - 如何查找数组中是否有重复元素? C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53594898/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com