Write a program to solve the word puzzle problem. Explain your code.
int namesearch( char p[], char t[] )
{
int i, j, k, m = strlen( p ), n = strlen( t ),
pFP, tFP;
pFP = fp( p, 0, m ); tFP = fp( t, 0, m );
for ( i = 0; i <= n-m; ++i ) {
if ( pFP == tFP ) {
for ( j = 0, k = i; j < m; ++j, ++k )
if ( p[ j ] != t[ k ] )
break;
if ( j == m ) return i;
}
else if ( i + m < n ) tFP += t[ i+m ] - t[ i ]; else break;
}
return -1;
}
int fp( char s[], int i, int m )
{
int j, sum;
sum = 0;
for ( j = i; j < m; ++j )
sum += s[ j ];
return sum;
}
Assume that the puzzle is given in the text file wpuzzle.txt. The first line contains two numbers (n and m) separated by a blank space. Those numbers are the rows and columns of the puzzle and are followed by n lines of m characters each. Assume that the words to be found are given in the text file words.txt, one word per line. No assumptions should be made as to whether or not the words appear in the puzzle. The program must fill (and print) a solution array with the words in the position and direction in which they were found
#define maxN 50
#define maxM 50
char puzzle[ maxN ][ maxM ], // puzzle array
puzsol[ maxN ][ maxM ], // solution array
line[ maxM + 1 ]; // input line from file
int n, // actual number of rows
m, // actual number of columns
maxOFnm, // number of elements in main diagonals
pFP; // fingerprint of a word (pattern)
void main()
{
FILE *fp;
int len;
if ( LoadPuzzle() ) {
ShowPuzzle();
if ( (fp = fopen( "words.txt", "r" )) != NULL ) {
while ( fgets( line, maxM + 1, fp ) != NULL ) {
len = removeNL( line );
FindWord( line, len );
}
fclose( fp );
ShowSolution();
}
}
}
Write a program to solve the word puzzle problem. Explain your code.
(Java Programming) The following is an old word puzzle: “Name a common word, besides tremendous, stupendous, and horrendous, that ends in dous.” If you think about this for a while it will probably come to you. However, we can also solve this puzzle by reading a text file of English words and outputting the word if it contains “dous” at the end. The text file “words.txt” contains 87314 English words, including the word that completes the puzzle. This file is...
Please write a python program for solving 8 puzzle problem using Iterative-Deepening-Search. please write in a manner that is easy to copy.
Write a C++ Program In C++, struct is a reserved word. Define the struct fruitType. Write a program that declares a variable of type fruitType, prompts the user to input data about a fruit, and outputs the fruit data. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID */ #include <iostream> #include <string> using namespace std; struct...
solve using the code provided
Write a program that will continuously read words from the user, word by word till the user enter "quit”, the program should print each word in reverse order. Sample Session: (User input in Red color) Enter a word: hello olleh Enter a word: Ahmad damhA Enter a word: quit Good Bye 9 dinclude <iostream> 10 dinclude <cstring> 11 using namespace std; 12 13 int main() { 14 15 char word(100); 16 cin>>word; 17 while (strcmp(word,...
IN JAVASCRIPT
5. Write the pseudo code to solve the following problem (10pts/10pts) You are asked to write a calculator program. Your calculator must perform Addition, Subtraction, Division and Multiplication. The user will enter two numbers and then an operator. If the user enters an operator other than the four mentioned the program will display an error message otherwise it will display the answer. Demonstrate use of an if statement
– Palindrome Game Please write a Java program to verify whether a given word is a palindrome. You must stop your program when the user enters ‘@’ character as the word. You may write a recursive program to solve this game, but you don’t have to. You may use a stack and/or a queue to solve this game, but you don’t have to. You must run 3 test cases for your program. Your test case #1 must look as follows:...
In python Please type the code
Question 4: Write a program that reads an English word from the user, and prints how many vowels and how many consonants it contains. Note: You may assume the letter Y is not a vowel. Sample output (2 different executions) Enter a word: test test has 1 vowels and 3 consonants Enter a word: Apple Apple has 2 vowels and 3 consonants.
Using Dev C++, write a program to solve the problem as stated below. Write a program will input a single integer value (all input will be exactly 8 digits long) and will store pairs of digits as individual integer values. The program will display the five 2-digit numbers as well as the average of these, each on their own line. Use a switch statement to print out Grade: and then either A (>=90), B ([80..89]), C ([70..79]), D ([60..69]) or...
a) What is a polarizer puzzle? Explain in your own words and using figure, the puzzle. b) Explain in your own words how can we measure the concentration of a solution using Optical techniques?
Be sure to include documentation in your program. Submit both your program code and a screenshot of your running program in a word processing document. Sam’s Subs, a sandwich shop, specializes in fast delivery of submarine sandwiches. Sam has hired you to write C++ programs for their business. Write a program that calculates the amount of change that a delivery driver owes a customer. For example, if the driver enters a sales amount of $6 and a cash received amount...