zoukankan      html  css  js  c++  java
  • 算法与数据结构实验题 9.1 哈希

    1、题目:

    2、解题思路:

    将每个子字符串中字母转换成数字,子串的数值作为数组的下标,只要两个数组的数组下标相同,则说明这两个子串相同,计数时不再加一。

    3、代码:

    #include<stdio.h>
    #include<cmath>
    #include<string>
    int count[1000000]={0};
    char str[1000000];
    int main()
    {
    	int n,m,k;
    	scanf("%d%d%d",&n,&m,&k);
    	scanf("%s",str);
    	int i,j=0;
    	int value[1000];
    	int counts=0;
    	for(i=0;i<n-k+1;i++)
    	{
    		int h=k,ans=0;
    		for(j=0;j<k;j++)
    		{
    			value[str[i+j]]=str[i+j]-96;
    			ans+=value[str[i+j]]*pow(10,h-1);
    			h--;
    		}
    		if(count[ans]==0)
    		{
    			count[ans]++;
    			counts++;
    		}
    	}
    	printf("%d
    ",counts);
    	return 0;
    }
  • 相关阅读:
    各种读取速度
    索引倒排
    清空mysql数据
    java随机读取文件
    移动文件
    输出字符串数组
    背包问题
    使用bloomfilter
    使用hash拆分文件
    判断文件的编码格式
  • 原文地址:https://www.cnblogs.com/laixiaolian/p/6015135.html
Copyright © 2011-2022 走看看