散列(hash):由关键字值,通过某函数(hash函数)直接计算出他在表中的位置
直接给出一个例子(例子的题目在b站):例子是根据给定模式字符串输出输入数组字符
#include<iostream>
#define maxsize 10001
using namespace std;
int main()
{
char s[maxsize];
int count[123] = {};
char dic[] = "PAtest";
gets(s);
for (int i = 0; s[i] != '\0'; i++)
++count[(int)s[i]];
while (1)
{
int flag = 0;
for (int i = 0; dic[i] != '\0'; i++)
{
if (count[(int)dic[i]] > 0)
{
cout << dic[i];
--count[(int)dic[i]];
flag = 1;
}
}
if (flag == 0)
break;
}
return 0;
}