char nodeslot[maxslot] = {0};
char hash(char value)
{
return (value & (maxslot -1));
}
//字符串过滤,去掉重复的字符,例如 输入:awaffqfqfcqfwqwfqfqccqwfdqqqqqqqqffffhifqfcnq 输出:awfqcdhin
int filter(char *in,char *out)
{
if(NULL == in){
return 0;
}
if(NULL == out){
return -1;
}
char *p = in;
while(*p != '\0'){
char val = hash(*p);
if(!nodeslot[val]){
*out = *p;
out++;
nodeslot[val] = 1;
}
p++;
}
*out++ = '\0';
return 0;
}
char *lmove(char *in,int *len)
{
if(NULL == in){
return NULL;
}
int length = strlen(in);
char *p = &in[length];
char *tail = p;
while(*p == ' ')p--;
while(p != in && *p != ' ')p--;
int word = tail - p ;
*len = word;
return p;
}
//字符串反序,例如:输入: I has a every good idea 输出:idea! good every a has I
int reverseoder(char *in,char *out)
{
if(NULL == in){
return 0;
}
if(NULL == out){
return -1;
}
int length = strlen(in);
while(length > 0){
int lsize = 0 ;
char *lp = lmove(in,&lsize);
memcpy(out,lp,lsize);
out += lsize;
*lp = '\0';
length -= lsize;
}
}