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

}

相关推荐
2501_924889557 小时前
商超高峰客流统计误差↓75%!陌讯多模态融合算法在智慧零售的实战解析
大数据·人工智能·算法·计算机视觉·零售
jingfeng5148 小时前
C++模板进阶
java·c++·算法
地平线开发者8 小时前
征程 6X | 常用工具介绍
算法·自动驾驶
地平线开发者8 小时前
理想汽车智驾方案介绍 2|MindVLA 方案详解
算法·自动驾驶
艾莉丝努力练剑9 小时前
【C语言16天强化训练】从基础入门到进阶:Day 7
java·c语言·学习·算法
地平线开发者9 小时前
LLM 中评价指标与训练概要介绍
算法·自动驾驶
小十一再加一9 小时前
【C初阶】自定义类型--结构体
c语言
Ghost-Face10 小时前
关于并查集
算法
flashlight_hi11 小时前
LeetCode 分类刷题:2529. 正整数和负整数的最大计数
python·算法·leetcode
花火|11 小时前
算法训练营day60 图论⑩ Bellman_ford 队列优化算法、判断负权回路、单源有限最短路
算法·图论