Hash table-Count the number of occurrences of a character

Source: Internet
Author: User

The first character that appears only once: finds the first occurrence of a character in a string. If input "Abaccdeff" then output b

Answer: Because the topic appeared and the number of occurrences of the character related. We can use a container to hold the number of occurrences of each character, which means that the function of this container is to implicitly a character into a number. So we use a hash table.

#include <QCoreApplication>#include<iostream>#include<QDebug>CharFindonlyonechar (Char*inputstring) {    if(inputstring==NULL) {        return ' /'; }    Const intHashsize= the;//represents a 256-character AssicUnsignedintHashtable[hashsize];//Hash Container//initializing a hash array     for(unsignedintI=0; i) {Hashtable[i]=0; }    Char*inputstring1=inputstring;  while(* (inputString1)! =' /')    {        //hashtable[* (inputstring1++)]++; //hashtable[* (INPUTSTRING1)] (such as hasttable[' a '] ' a ' will become an ASCII integer value ofhashtable[* (inputString1)]=hashtable[* (inputString1)]+1; InputString1++; } inputString1=inputstring;  while(*inputstring1!=' /')    {        if(hashtable[*inputstring]==1)        {            return*inputstring; } inputstring++; }    return ' /';}intMainintargcChar*argv[])    {Qcoreapplication A (argc, argv);     Test (); Std::cout<<findonlyonechar ("Abaccdeff"); System ("Pause"); returna.exec ();}

Hash table-Count the number of occurrences of a character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.