Alkalmak‎ > ‎2017-18-as tanév‎ > ‎11. alkalom‎ > ‎

Hash függvény

#include <stdio.h>
#include <stdlib.h>

unsigned int hash(unsigned char *str) {
    unsigned int hash = 5381;
    int c;

    while (c = *str++)
        hash = ((hash << 5) + hash) + c;

    return hash;
}

int main(int argc, char** argv) {
    char c[51];
    while(1) {
        scanf("%50s", c);
        printf("0x%08x\n", hash(c));
    }
    return EXIT_SUCCESS;
}