# Contains? & ltstdio.h & gt
# Contains? & lttime.h & gt
# Definition? Max. 1 1
# Definition? n? eight
int? Hash table [max];
int? func(int? Value)
{
Return? Value? %? Max? /* Hash function */
}
int? Search (int? Key) /* User-defined function for hash query */
{
int? pos,? t;
pos? =? Func (key); ? /* Location determined by hash function */
t? =? pos? /*t Store the determined location */
What time? (hash table [t]? ! =? Keys? & amp& amp? Hash table [t]? ! =-? 1)
/* If the location is not equal to the keyword to be searched and is not empty */
{
t? =? (t? +? 1)? %? Max? /* Find the next position by linear detection */
What if? (pos? ==? t)
/* If it returns to the original position obtained by the hash function after repeated detection, it means that the number to be searched does not exist */
Return-? 1;
}
What if? (hash table [t]? ==-? 1)
/* If the detected location is-1, the number to be searched does not exist */
Return? NULL
other
Return? t;
}
Invalid? creathash(int? Key) /* User-defined function creates hash table */
{
int? pos,? t;
pos? =? Func (key); ? /* The hash function determines the location of the element */
t? =? pos
What time? (hash table [t]? ! =-? 1)
/* If there is an element at this position, perform linear detection, and then hash */
{
t? =? (t? +? 1)? %? Max
What if? (pos? ==? t)
/* If the location determined after conflict processing is the same as the original location, the hash table is full */
{
printf("hash? Table? Is it? Full \ n ");
Return? ;
}
}
Hash table [t]? =? Key; ? /* Place the element in a definite position */
}
Master ()
{
int? flag[50];
int? Me? j,? t;
For what? (me? =? 0; ? Me? & lt? Max? i++)
hashtable[i]? =-? 1;
/* The initial positions in the hash table are all set to-1*/
For what? (me? =? 0; ? Me? & lt? 50; ? i++)
Mark [i]? =? 0;
/* All numbers under 50 are marked as 0*/
Srand ((unsigned? long)time(0)); ? /* Use system time as a seed to generate random numbers */
Me? =? 0;
What time? (me? ! =? n)
{
t? =? Rand ()? %? 50; ? /* Generate a random number within 50 and assign it to t*/
What if? (flag[t]? ==? 0)
/* Check whether T has been generated */
{
creat hash(t); ? /* Call function to create hash table */
printf("%2d:",? t); ? /* Output this element */
For what? (j? =? 0; ? j? & lt? Max? j++)
printf("(%2d)?" ,? hashtable[j]);
/* Output the contents of the hash table */
printf(" \ n ");
flag[t]? =? 1; ? /* Mark the generated number as 1*/
i++; ? /* I added it myself */
}
}
Printf ("Please? Input? Number? Which one? Do what? What about you? Want it? Where to? Search: ");
scanf("%d ",& ampt); ? /* Enter the element to find */
What if? (t? & gt? 0? & amp& amp? t? & lt? 50)
{
Me? =? Search (t); ? /* Call Hash Lookup Search */
What if? (me? ! =-? 1)
Printf ("Success! That? Location? Yes: %d\n ",i);
/* If the element is found, output its location */
other
Printf ("Sorry, no? I found it! ”);
/* No output prompt information found */
}
other
Printf ("input? Wrong! ”);
Experiment 3
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
Int judge(long n) /* Judge whether a number is palindrome */
{
Int i, len, half/* defines a variable as a basic integer */
char a[20]; /* Define array A as character type */
ltoa(n,a, 10); /* Convert the long integer n into a string and store it in the array A */
len = strlen(a); /* Get the length of array A */
half = len/2;
for(I = 0; I< half; i++)
If (a[i]! = one [-len])
? /* Judge whether the characters in the corresponding positions are the same */
Break;
? /* If you don't want to jump out of the loop together */
If (i>= half)
Returns1;
? /* is the palindrome number, and returns 1*/
other
Returns 0;
? /* is not a palindrome, and returns 0*/
}
Master ()
{
Dragon n;
clr SCR();
scanf("%ld ",& ampn);
Printf ("Result: \ n");
If (judge (n))
printf(" n=%4ld \n ",n);
getch();
}