Public feed #378760

Mine

public text v1 · immutable
Raw Edit
·published 2007-03-02 19:15 UTC
rendered paste body
char* freqHash(char *stringa){
    char* result;
    int l,i,j,trovato,value;
    l=strlen(stringa);
    result = (char *) malloc(sizeof(char) * (l+1));
    value = 0;

    for (i=0; i<l; i++) {
        trovato = -1;
        for (j=i-1; j!=-1; j--) {
            if (stringa[j] == stringa[i]) trovato = j;
        }
        if (trovato != -1){
            result[i] = result[trovato];
        } else {
            result[i] = value+48;
            value++;
        }
        
    }
    result[l+1] = '\0';
    
    return result;
}