哈希算法 c语言

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

// 哈希函数
unsigned int hash_function(const char *str) {
    unsigned int hash = 0;
    while (*str) {
        hash = (hash * 31 + *str) % 1000;
        str++;
    }
    return hash;
}

int main() {
    const char *str1 = "Hello";
    const char *str2 = "World";

    unsigned int hash1 = hash_function(str1);
    unsigned int hash2 = hash_function(str2);

    printf("String: %s, Hash: %u\n", str1, hash1);
    printf("String: %s, Hash: %u\n", str2, hash2);

    return 0;
}

相关推荐

  1. 算法 c语言

    2024-02-10 09:04:01       47 阅读
  2. 手动数字表-C语言

    2024-02-10 09:04:01       44 阅读
  3. C语言实现

    2024-02-10 09:04:01       35 阅读
  4. 算法

    2024-02-10 09:04:01       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-10 09:04:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-10 09:04:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-10 09:04:01       87 阅读
  4. Python语言-面向对象

    2024-02-10 09:04:01       96 阅读

热门阅读

  1. 即大而全又小而美

    2024-02-10 09:04:01       45 阅读
  2. Gradle IDEA 乱码

    2024-02-10 09:04:01       55 阅读
  3. 突破编程_C++_基础教程(类的基础知识)

    2024-02-10 09:04:01       44 阅读
  4. PyTorch: torch.max()函数详解

    2024-02-10 09:04:01       50 阅读
  5. 语义分割任务的准确率计算:基于PyTorch实现

    2024-02-10 09:04:01       58 阅读
  6. ARM交叉编译搭建SSH

    2024-02-10 09:04:01       51 阅读
  7. 并发、串行与同步、异步

    2024-02-10 09:04:01       51 阅读
  8. 微信小程序:父组件调用子组件的方法

    2024-02-10 09:04:01       48 阅读
  9. itextpdf使用:使用PdfReader添加图片水印

    2024-02-10 09:04:01       54 阅读
  10. MyBatis-Plus 实现分页

    2024-02-10 09:04:01       48 阅读
  11. Lua metatable & metamethod

    2024-02-10 09:04:01       54 阅读