Le support aux utilisateurs et les demandes de création de comptes externes doivent être faites depuis les issues du projet GitLab HEFR (https://gitlab.forge.hefr.ch/forge-hefr/gitlab-hefr)

Commit 6a5b1334 authored by Jacques Supcik's avatar Jacques Supcik
Browse files

Add S18

parent d20308f5
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>s18</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
[199]els1f-bapst>java Boggle
Enter puzzle file:
puz.txt
Opened puz.txt
Enter dictionary name:
words.txt
Opened words.txt
Reading files...
Solving...
Found 'disk' ending at 4 4
Found 'invalid' ending at 3 9
Found 'invalidate' ending at 3 12
Found 'valid' ending at 3 9
Found 'validate' ending at 3 12
Found 'donate' ending at 3 12
Found 'date' ending at 3 12
Found 'dater' ending at 3 13
Found 'terse' ending at 5 13
Found 'sink' ending at 4 4
Found 'slew' ending at 6 13
Found 'scale' ending at 5 13
Found 'sewn' ending at 7 13
Found 'bask' ending at 4 4
Found 'wood' ending at 3 9
Found 'sale' ending at 5 13
Found 'lied' ending at 6 10
Found 'less' ending at 4 12
Found 'else' ending at 3 12
Found 'sewn' ending at 7 13
Found 'mask' ending at 4 4
Found 'deal' ending at 5 12
Found 'wile' ending at 5 13
Found 'myth' ending at 8 3
Found 'maim' ending at 6 5
Found 'math' ending at 8 3
Found 'wage' ending at 9 13
Found 'wadi' ending at 7 15
Found 'tofu' ending at 9 19
Found 'they' ending at 9 2
Found 'dawn' ending at 7 13
Found 'wavy' ending at 8 5
Found 'fawn' ending at 7 13
Found 'alibi' ending at 12 16
Found 'mesh' ending at 8 3
Found 'lint' ending at 11 15
Found 'twin' ending at 11 16
Found 'robin' ending at 11 16
Found 'robe' ending at 13 17
Found 'robin' ending at 11 16
Found 'babe' ending at 10 3
Found 'blab' ending at 12 1
Found 'bike' ending at 13 17
Found 'alba' ending at 11 2
Found 'labia' ending at 13 0
Found 'wind' ending at 14 6
Found 'bury' ending at 16 12
Found 'burp' ending at 15 13
Found 'honk' ending at 15 2
Found 'hind' ending at 14 6
Found 'hint' ending at 15 7
Found 'into' ending at 16 7
Found 'tofu' ending at 17 8
Found 'cycle' ending at 18 11
Found 'into' ending at 16 7
Found 'oint' ending at 15 7
Found 'rice' ending at 17 11
Found 'shod' ending at 18 7
Found 'saint' ending at 15 7
Found 'join' ending at 15 6
Found 'joint' ending at 15 7
Found 'juicy' ending at 16 10
Found 'juice' ending at 17 11
Found 'icky' ending at 16 12
Found 'prism' ending at 17 14
[200]els1f-bapst>
fozepdkdnqlhfejdzksc
cfykdxnlorwvfwavbmyq
clxjrgntqhvuowgrtufh
nbdinvalidateryxxuqp
dmmsksjdooncssvrznss
flsjbahawxsalesvwdbl
sqpkimdjzxdeiwqmwxou
wgukamfjqiwkynwizzty
xxehtyvrtklqsgaduhom
smyszwaywwyvtefozafu
mtmebojkwxkqloimhlmf
ikabpgsqizksrzztnirl
ibbtlkgsvuzwfbhwiboq
aaltzkmnsdacgawukeoh
yonfpwdxxrqxubqtnfgh
khkrhintdbcorpwhlzgi
tyinbyiofryqykjhswci
zgwrwsajuiceicmsirpo
fxyfjhodfqlexhxvcxgy
ganperxhfyrnxpsgyhjd
package s18;
import java.io.*;
// Puzzle class interface: solve word search puzzle
//
// CONSTRUCTION: with no initialzier
// ******************PUBLIC OPERATIONS******************
// int solvePuzzle( ) --> Print all words found in the
// puzzle; return number of matches
public class WordSrch
{
private static final int MAX_ROWS = 64;
private static final int MAX_COLUMNS = 64;
private static final int MAX_WORDS = 100000;
// ------------------------------------------------------------
/**
* Constructor for WordSrch class.
* Prompts for and reads puzzle and dictionary files.
*/
public WordSrch( ) {
puzzleStream = openFile( "Enter puzzle file" );
wordStream = openFile( "Enter dictionary name" );
System.out.println( "Reading files..." );
readPuzzle( );
readWords( );
}
// ------------------------------------------------------------
/**
* Routine to solve the word search puzzle.
* Performs checks in all eight directions.
* @return number of matches
*/
public int solvePuzzle( ) {
int matches = 0;
for( int r = 0; r < rows; r++ )
for( int c = 0; c < columns; c++ )
for( int rd = -1; rd <= 1; rd++ )
for( int cd = -1; cd <= 1; cd++ )
if( rd != 0 || cd != 0 )
matches += solveDirection( r, c, rd, cd );
return matches;
}
// ------------------------------------------------------------
/**
* Search the grid from a starting point and direction.
* @return number of matches
*/
private int solveDirection( int baseRow, int baseCol,
int rowDelta, int colDelta ) {
String charSequence = "";
int numMatches = 0;
int searchResult;
charSequence += theBoard[ baseRow ][ baseCol ];
for( int i = baseRow + rowDelta, j = baseCol + colDelta;
i >= 0 && j >= 0 && i < rows && j < columns;
i += rowDelta, j += colDelta ) {
charSequence += theBoard[ i ][ j ];
searchResult = prefixSearch( theWords, charSequence, numEntries );
if( !theWords[ searchResult ].startsWith( charSequence ) )
break;
if( theWords[ searchResult ].equals( charSequence ) ) {
numMatches++;
System.out.println( "Found " + charSequence + " at " +
baseRow + " " + baseCol + " to " +
i + " " + j );
}
}
return numMatches;
}
// ------------------------------------------------------------
/**
* Performs the binary search for word search
* using one comparison per level.
* Assumes a and n are OK.
* @param a the sorted array of strings.
* @param x the string to search for.
* @param n the number of strings in the array.
* @return last position examined;
* this position either matches x, or x is
* a prefix of the mismatch, or there is no
* word for which x is a prefix.
*/
private static int prefixSearch( String [ ] a, String x, int n ) {
int low = 0;
int high = n - 1;
while( low < high ) {
int mid = ( low + high ) / 2;
if( a[ mid ].compareTo( x ) < 0 )
low = mid + 1;
else
high = mid;
}
return low;
}
// ------------------------------------------------------------
/**
* Print a prompt and open a file.
* Retry until open is successful.
* Program exits if end of file is hit.
*/
private BufferedReader openFile( String message ) {
String fileName = "";
FileReader theFile;
BufferedReader fileIn = null;
do {
System.out.println( message + ": " );
try {
fileName = in.readLine( );
if( fileName == null )
System.exit( 0 );
theFile = new FileReader( fileName );
fileIn = new BufferedReader( theFile );
}
catch( IOException e ) {
System.err.println( "Cannot open " + fileName );
}
} while( fileIn == null );
System.out.println( "Opened " + fileName );
return fileIn;
}
// ------------------------------------------------------------
/**
* Routine to read the grid.
* Checks to ensure that the grid is rectangular.
* Checks to make sure that capacity is not exceeded is omitted.
*/
private void readPuzzle( ) {
String oneLine;
try {
if( ( oneLine = puzzleStream.readLine( ) ) == null ) {
rows = 0;
return;
}
columns = oneLine.length( );
for( int i = 0; i < columns; i++ )
theBoard[ 0 ][ i ] = oneLine.charAt( i );
for( rows = 1;
( oneLine = puzzleStream.readLine( ) ) != null;
rows++ ) {
if( oneLine.length( ) != columns )
System.err.println( "Puzzle is not rectangular" );
for( int i = 0; i < columns; i++ )
theBoard[ rows ][ i ] = oneLine.charAt( i );
}
} catch( IOException e ) { }
}
// ------------------------------------------------------------
/**
* Routine to read the dictionary.
* Error message is printed if dictionary is not sorted.
* Check is made to avoid exceeding maxWords.
*/
private void readWords( ) {
numEntries = 0;
try {
while( ( theWords[ numEntries ] = wordStream.readLine( ) ) != null ) {
if( numEntries != 0 &&
theWords[numEntries].compareTo( theWords[numEntries-1] ) < 0 ) {
System.err.println( "Dictionary is not sorted... skipping" );
continue;
} else if( ++numEntries >= MAX_WORDS )
break;
}
if( wordStream.ready( ) )
System.err.println( "Warning: unread data - increase MAX_WORDS" );
}
catch( IOException e ) { }
}
// ------------------------------------------------------------
// Cheap main
public static void main( String [ ] args ) {
WordSrch p = new WordSrch( );
System.out.println( "Solving..." );
p.solvePuzzle( );
}
// ------------------------------------------------------------
private int rows;
private int columns;
private int numEntries;
private char theBoard[ ][ ] = new char[ MAX_ROWS ][ MAX_COLUMNS ];
private String [ ] theWords = new String[ MAX_WORDS ];
private BufferedReader puzzleStream;
private BufferedReader wordStream;
private BufferedReader in =
new BufferedReader( new InputStreamReader( System.in ) );
}
This diff is collapsed.
hint
juice
sales
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment