大数据查重-哈希表应用2

大数据查重-哈希表应用

模拟问题

        有一个字符串,这个字符串里有重复的字符,也有没有重复的字符,让你找出来第一个没有重复出现过的字符。

#include 
#include 
#include  
#include 
#include 
#include 
#include 
using namespace std;

int main()
{
    string src = "jjhfgiyuhrtytrs";
    //让你找出来第一个没有重复出现过的字符
    unordered_map m;
    for (char ch : src)
    {
        m[ch]++;
    }

    for (char ch : src)
    {
        if (m[ch] == 1)
        {
            cout << "第一个没有重复出现过的字符是:" << ch << endl;
            return 0;
        }
    }

    cout << "所有字符都有重复出现过!" << endl;
    return 0;
}

运行结果

大数据查重-哈希表应用2_第1张图片

你可能感兴趣的:(算法,数据结构,大数据,散列表,数据结构,算法)