[cpp]
#include<stdio.h>
#include<string.h>
#include<assert.h>
unsigned int hashTable[256];
char queue[256];
char solve(char *str)
{
unsigned int i = 0;
memset(hashTable, 0, sizeof(hashTable));
memset(queue, '0', sizeof(queue));
int index = 0;
for(i=0; i<strlen(str); i++)
{
int loc = (int)str[i];
if(hashTable[loc] == 0)
{
queue[index++] = str[i];
hashTable[loc] = 1;
}
else
{
hashTable[loc] += 1;
}
}
for(i=0; i<index; i++)
{
int loc = (int)queue[i];
if(hashTable[loc] == 1)
return queue[i];
}
return NULL;
}
void testSize()
{
//分辨sizeof與strlen的區別
char *s = "abcdefg";
printf("%d %d\n", sizeof(s), strlen(s));//4 7
char ss[] = "abcdefg";
printf("%d %d\n", sizeof(ss), strlen(ss));// 8 7
}
void test()
{
char *str = "abaccdeff";
char c = solve(str);
printf("%c\n", c);
}
int main()
{
testSize();
test();
return 0;
}