Check whether spelling is correct. Give you a dictionary, and then give you the words you want to query to determine whether a word is correct. The following rules apply: 1. the dictionary contains the word 2, which deletes a letter, 3 adds a letter 4, and replaces any letter.
Algorithm: in fact, there is no algorithm, that is, scanning the dictionary and comparing the length of the target string and the dictionary string, in three cases: equal length, one less, one more letter.
Code:
# Include <stdio. h>
# Include <string. h>
Char STR [2, 10010] [20], s [20];
Int used [10010], N;
Int judge ()
{
Int I, J, K, L, M;
Int Len;
Len = strlen (s );
For (I = 0; I <n; I ++)
{
L = strlen (STR [I]);
If (LEN = L) // same length
{
If (strcmp (STR [I], S) = 0)
Return 1;
Else
{
K = 0;
For (j = 0; j <Len; j ++)
{
If (STR [I] [J]! = S [J])
K ++;
}
If (k = 1)
{
Used [I] = 1;
Continue;
}
}
}
Else
{
If (LEN = L-1) // less than 1
{
K = 0; M = 0;
For (j = 0; j <Len; j ++)
{
While (k <L)
{
If (s [J] = STR [I] [k])
{
M ++;
K ++; // do not forget to move back when they are equal. Determines the longest common substring.
Break;
}
Else
K ++;
}
}
If (M = Len)
{
Used [I] = 1;
Continue;
}
}
Else if (LEN = L + 1)
{
K = 0; M = 0;
For (j = 0; j <L; j ++)
{
While (k <Len)
{
If (s [k] = STR [I] [J])
{
M ++;
K ++;
Break;
}
Else
K ++;
}
}
If (M = L)
{
Used [I] = 1;
Continue;
}
}
}
}
Return 0;
}
Int main ()
{
Int I, J;
N =-1;
While (1)
{
N ++;
Scanf ("% s", STR [N]);
If (STR [N] [0] = '#')
Break;
}
While (1)
{
J = 0;
Memset (used, 0, sizeof (used ));
Scanf ("% s", S );
If (s [0] = '#')
Break;
If (Judge ())
Printf ("% s is correct/N", S );
Else
{
Printf ("% s:", S );
For (I = 0; I <n; I ++)
{
If (used [I] = 1)
{
J = 1;
Printf ("% s", STR [I]);
}
}
If (j = 0)
Printf (""); // note that if it is not correct, spaces are still required.
Printf ("/N ");
}
}
Return 0;
}