Converted java file to C++ file
FindWordInMaze.cpp
-------------------------------------
#include<bits/stdc++.h>
#define MAX 10
using namespace std;
int row,col;
bool visited[MAX][MAX];
class FindWordInMaze
{
private:
vector<vector<char>>grid;
vector<string>words;
unordered_set<string>foundWords;
public:
FindWordInMaze(vector<vector<char>>grid)
{
this->grid = grid;
words.push_back("START");
words.push_back("NOTE");
words.push_back("SAND");
words.push_back("STONED");
sort(words.begin(),words.end());
}
bool isValidIndex(int i,int j);
void findWords(string wordTillNow, int i, int j);
void findWordsFromLocation(int i, int j);
void findWords();
};
bool FindWordInMaze::isValidIndex(int i, int j)
{
return (i>=0 && i<row && j>=0 &&
j<col && !visited[i][j]);
}
void FindWordInMaze::findWords(string wordTillNow, int i, int
j)
{
if(visited[i][j] || wordTillNow.length()>6)
{
return;
}
wordTillNow = wordTillNow + grid[i][j];
visited[i][j] = true;
if(find(words.begin(),words.end(),wordTillNow)!=words.end()
&& wordTillNow.length())
{
foundWords.insert(wordTillNow);
}
for(int rowOffset = -1; rowOffset<2; rowOffset++)
{
for(int colOffset = -1; colOffset<2; colOffset++)
{
if(rowOffset!=0 || colOffset!=0)
{
if(isValidIndex(i+rowOffset,j+colOffset))
{
findWords(wordTillNow, i+rowOffset,j+colOffset);
}
}
}
}
visited[i][j] = false;
}
void FindWordInMaze::findWordsFromLocation(int i, int j)
{
findWords("",i,j);
}
void FindWordInMaze::findWords()
{
for(int i=0;i<grid.size();i++)
{
for(int j=0;j<grid[i].size();j++)
{
findWordsFromLocation(i,j);
}
}
for(string w: foundWords)
{
cout<<w<<" ";
}
}
int main()
{
vector<vector<char>>grid={ { 'M', 'S', 'E', 'F'},
{ 'R', 'A', 'T', 'D'},
{ 'L', 'O', 'N', 'E'},
{ 'K', 'A', 'F', 'B'}};
row = grid.size();
col = grid[0].size();
FindWordInMaze finder(grid);
finder.findWords();
return 0;
}
import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class FindWordInMaze { private char grid[][]; private...
What is the output of the following program? import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test implements Comparable<Test> private String[] cast; public Test( String[] st) cast = st; public int compareTo( Test t) if ( cast.length >t.cast.length ) t return +1; else if cast.length < t.cast.length return -1; else return 0; public static void main( String[] args String[] a"Peter", "Paul", "Mary" String[] b_ { "Мое", ''Larry", "Curly", String [ ] c = { ·Mickey", "Donald" }; "Shemp" }; List<Test>...
Please use my code to implement the above instructions. My Grid class: import java.util.ArrayList; import java.util.Collections; class Grid { private boolean bombGrid[][]; private int countGrid[][]; private int numRows; private int numColumns; private int numBombs; public Grid() { this(10, 10, 25); } public Grid(int rows, int columns) { this(rows, columns, 25); } public Grid(int rows, int columns, int numBombs) { this.numRows = rows; this.numColumns = columns; this.numBombs = numBombs; createBombGrid(); createCountGrid(); } public int getNumRows() { return numRows;...
Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver { public static String solve(char[][] grid) { // TODO /* * 1. Construct a graph using grid * 2. Use BFS to find shortest path from start to finish * 3. Return the sequence of moves to get from start to finish */ // Hardcoded solution to toyTest return...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null;...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null; //TODO...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...
How can I make a test case with Junit? import java.util.ArrayList; import board.Board; public class Pawn extends Piece{ public Pawn(int positionX, int positionY, boolean isWhite) { super("P", positionX, positionY, isWhite); } @Override public String getPossibleMoves() { ArrayList<String> possibleMoves = new ArrayList<>(); //check side, different color pawns go on different ways if(isWhite) { if(positionX != 7 && positionY != 0) { ...
Consider the Automobile class: public class Automobile { private String model; private int rating; // a number 1, 2, 3, 4, 5 private boolean isTruck; public Automobile(String model, boolean isTruck) { this.model = model; this.rating = 0; // unrated this.isTruck = isTruck; } public Automobile(String model, int rating, boolean isTruck) { this.model = model; this.rating = rating; this.isTruck = isTruck; } public String getModel()...
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...