[Cpp]
/*************************************** *****
* Find the first character that appears only once in a string. If abaccdeff is input, B is output.
**************************************** *****/
# Include <stdio. h>
# Include <string. h>
# Define N 256
Int charHash [N] = {0 };
Void initCharHash (const char * s)
{
While (* s)
{
CharHash [* s] ++;
S ++;
}
}
Char findFirstOnceChar (const char * s)
{
While (* s)
{
If (charHash [* s] = 1)
{
Return * s;
}
S ++;
}
Return 0;
}
Int main (void)
{
Char * str = "abaccdeff ";
InitCharHash (str );
Printf ("% c \ n", findFirstOnceChar (str ));
Return 0;
}
/*********
B
Process returned 0 (0x0) execution time: 1.254 s
Press any key to continue.
**********/
/*************************************** *****
* Find the first character that appears only once in a string. If abaccdeff is input, B is output.
**************************************** *****/
# Include <stdio. h>
# Include <string. h>
# Define N 256
Int charHash [N] = {0 };
Void initCharHash (const char * s)
{
While (* s)
{
CharHash [* s] ++;
S ++;
}
}
Char findFirstOnceChar (const char * s)
{
While (* s)
{
If (charHash [* s] = 1)
{
Return * s;
}
S ++;
}
Return 0;
}
Int main (void)
{
Char * str = "abaccdeff ";
InitCharHash (str );
Printf ("% c \ n", findFirstOnceChar (str ));
Return 0;
}
/*********
B
Process returned 0 (0x0) execution time: 1.254 s
Press any key to continue.
**********/