当前位置: 首页 > news >正文

哈希算法 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;
}

http://www.lryc.cn/news/296934.html

相关文章:

  • 新版MQL语言程序设计:组合模式的原理、应用及代码实现
  • 代码随想录算法训练营第25天 | 216.组合总和III ,17.电话号码的字母组合
  • Rust 第一个rust程序Hello Rust️
  • 高斯消去法 | LU分解 | PA=LU分解(MatLab)
  • Linux笔记之expect和bash脚本监听输出并在匹配到指定字符串时发送中断信号
  • 项目02《游戏-12-开发》Unity3D
  • 记一次面试题
  • Rust入门2——随机数
  • c#: 表达式树的简化
  • 13. UE5 RPG限制Attribute的值的范围以及生成结构体
  • UE4运用C++和框架开发坦克大战教程笔记(十九)(第58~60集)完结
  • ModuleNotFoundError: No module named ‘_ctypes‘报错解决方案
  • 【服务器数据恢复】服务器RAID模块硬件损坏的数据恢复案例
  • spring boot3x登录开发-上(整合jwt)
  • git 克隆拉取代码出现私钥权限问题。
  • 【5G NR】【一文读懂系列】移动通讯中使用的信道编解码技术-卷积码原理
  • 揭开Markdown的秘籍:标题|文字样式|列表
  • 移动最小二乘法
  • 【LeetCode】37. 解数独(困难)——代码随想录算法训练营Day30
  • VUE学习——属性绑定
  • vue3 之 通用组件统一注册全局
  • [Java][算法 双指针]Day 02---LeetCode 热题 100---04~07
  • 【问题解决】如何将一个服务器的docker迁移到另一个服务器
  • C++单例模式详解
  • LLM应用开发与落地:流式响应
  • 神经网络 | 基于 CNN 模型实现土壤湿度预测
  • 江科大STM32 终
  • 《MySQL 简易速速上手小册》第10章:未来趋势和进阶资源(2024 最新版)
  • Stable Diffusion 模型下载:GhostMix(幽灵混合)
  • django解决Table ‘xx‘ already exists的方法