3个大写字母出现次数

3个大写字母出现次数
hash最初步

#include<cstdio>
int hashFunc(char str[],int n){
	int sum=0;
	for(int i=0;i<n;i++){
		sum=sum*26+(str[i]-'A');
	}
	return sum;
}
int main(){
	int m,n,hashtable[26*26*26+10];
	char str[100];
	scanf("%d%d",&m,&n);
	for(int i=0;i<m;i++){
		scanf("%s",str);
		int temp=hashFunc(str,3);
		hashtable[temp]++;
	}
	
	for(int j=0;j<n;j++){
		scanf("%s",str);
		int temp=hashFunc(str,3);
		printf("%s::%d",str,hashtable[temp]);
	}
	
	
	
	
	return 0;
}
发布了27 篇原创文章 · 获赞 1 · 访问量 1673

猜你喜欢

转载自blog.csdn.net/qq_37959151/article/details/86319450