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