Implement the following pseudocode

Assignment Help Data Structure & Algorithms
Reference no: EM13945515

public class WordSearch {

private static ArrayList<String> board = new ArrayList<String>();
private static Scanner scanner;

public static void readBoard() {
String line;
while (true) {
line = scanner.nextLine();
if (line.equals(""))

break;
board.add(line.replaceAll(" ","").toUpperCase());
}
}

public static void printBoard() {
int rows = getRows();
for (int row=0; row<rows; row++)
System.out.println(board.get(row));
}

public static int getRows() {
return board.size();
}

public static int getCols() {
return board.get(0).length();
}

public static void createScanner() {
try {
scanner = new Scanner(new java.io.File("WordSearchInput.txt"));
} catch (Exception e) {
System.out.println();
System.exit(1);
}
}

public static void processWords() {
while (scanner.hasNext()) {
String word = scanner.next();
findWord(word);
}
}

public static void findWord(String word) {
int rows = getRows();
int cols = getCols();
for (int row=0; row<rows; row++)
for (int col=0; col<cols; col++)
findWord(word,row,col);
}

public static void findWord(String word, int row, int col) {
for (int drow=-1; drow<=1; drow++)
for (int dcol=-1; dcol<=1; dcol++)
findWord(word,row,col,drow,dcol);
}

public static void findWord(String word, int row, int col, int drow, int dcol) {
int rows = getRows();
int cols = getCols();
for (int offset=0; offset<word.length(); offset++) {
int targetRow = row + offset*drow;
int targetCol = col + offset*dcol;
if ((targetRow < 0) ||
(targetRow >= rows) ||
(targetCol < 0) ||
(targetCol >= cols))

return;
char boardChar = board.get(targetRow).charAt(targetCol);
char wordChar = word.charAt(offset);
if (boardChar != wordChar)
// mismatch, so we're done
return;
}
System.out.printf("%s at %d,%d direction %d,%dn",
word, row, col, drow, dcol);
}

public static void main(String[] args) {
createScanner();
readBoard();

Reference no: EM13945515

Questions Cloud

How would that ratio change if the firm : How would that ratio change if the firm can earn only a 10% rate of return on its investments?
Error code in unning this program in raptor : I need an input statement that would allow the user to input any day of the week for steps walked and be able to input any number for step walked on any day of the week.
Write a short note on probability sampling methods : What techniques would you suggest in an effort to minimize and detect subject dishonesty in a Social Science research? Write a short note on probability and non-probability sampling methods
How should the interests of competing groups be balanced : Should environmental groups play a role in preserving those regions threatened by human encroachment, even if it is jeopardizing interests of the economic growth? How should the interests of competing groups be balanced?
Implement the following pseudocode : private static ArrayList board = new ArrayList ();
What should the stock price be today : If the discount rate is 15% and the steady growth rate after 3 years is 4%, what should the stock price be today?
A two digit number is such that the product of its digits is : A two digit number is such that the product of its digits is 35. When 18 is added to the number, the digits interchange their places. Find the number. A motor boat whose speed is 18 km/hr in still water takes 1 hour more to go 24 km upstream than to ..
What human impacts on natural cycling process of ecosystems : Identify a natural ecosystem in Arizona which you live or one near to where you live? How does this ecosystem support you? What are some human impacts on the natural cycling process of ecosystems in your community?
Write assembly language program for the marie processor : Please refer to the attachment for the general structure of the assembly language source code and more specifications regarding the assembly program

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Question 1a explain the meaning of each of the following

question 1a explain the meaning of each of the following pointer declarations-i float a -0.137float pa ampaii double

  Creating sql statements

Create three SQL statements: the 1st statement should add pending amounts to appropriate accounts, the second statement should subtract the pending amounts from appropriate accounts,

  Construct an entity-relationship model for the database

Construct an entity-relationship (ER) model for the database. Make sure you include in your model details of entities, relationships, attributes, keys and limits in participation.

  Write a pseudocode for divide-and-conquer algorithm

Write a pseudocode for divide-and-conquer algorithm for finding the values of both the largest and smallest elements in an array of n numbers

  Algorithm to concatenate string in single binary search tree

Create algorithm which concatenates T1 and T2 into single binary search tree. Worst case running time must be O(h).

  Computing the total dollar sales

A corporation has a product line that includes five items that sell for $100, $75, $120, $150, and $35. There are four salespersons working for this corporation,

  Goal-seeking analysis and simulation

Perform a what-if analysis to determine the maximum total profit that could be achieved if only rye (no wheat) is planted, given the cost and time constraints.

  Find the kth largest value in an unsorted array of n element

find the kth largest value in an unsorted array of N elements. Estimate the running time. It should be better than quick sort running time.

  Explaining diffie-hellman public-key algorithm

Use the Diffie-Hellman public-key algorithm to exchange secret keys.

  Creating villian

Announce a new Villian called sharpay who has a wit of 24, a stealth of sixteen, and who has currently claimed three victims: Chad, Troy, and Gabriella.

  Distributed system algorithms

Distributed system algorithms - Leader Election (id),  In: Processor's id , Out: LEADER if processor has largest id, NOT_LEADER if otherwise

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd