#include <>
using namespace std;
int FindFirstUniqueChar(char* szString,char* uniqueChar)
{
if((szString == NULL) (uniqueChar == NULL))
return -1;
int indexPos[257];
int count[257];
char* temp = szString;
memset(uniqueChar,0,(sizeof(uniqueChar)/sizeof(&uniqueChar[0])));
memset(count,0,257*sizeof(int));
memset(indexPos,-1,257*sizeof(int));
while(*temp)
{
count[*temp]++;
if( indexPos[*temp] == -1)
indexPos[*temp] = (temp - szString);
temp++;
}
int idx = 256;
for(int i = 0; i < 257; i++)
{
if((indexPos[i] <= idx) && (count[i] == 1))
{
*uniqueChar = char(i);
*(uniqueChar+1) = '\0';
idx = i;
}
}
if((idx != 256) && (*uniqueChar != NULL))
{
return 0;
}
return -2;
}
int main ()
{
char ch[2];
int ret = FindFirstUniqueChar("tomato",ch);
return 0;
}
Subscribe to:
Post Comments (Atom)
.jpg)
No comments:
Post a Comment