Word Puzzles
Time Limit: 5000MS |
Memory Limit: 65536K |
Total Submissions: 10782 |
Accepted: 4076 |
Special Judge |
Description
Word puzzles is usually simple and very entertaining for all ages. They is so entertaining this Pizza-hut company started using table covers with Word puzzles printed on them, possibly wit H the intent to minimise their client's perception of any possible delay in bringing them their order.
Even though word puzzles may is entertaining to solve by hand, they if become boring when they get very large. Computers do not yet get bored in solving tasks, therefore we thought you could devise a program to Speedup (hopefully!) s Olution finding in such puzzles.
The following figure illustrates the Pizzahut puzzle. The names of the pizzas to being found in the puzzle Are:margarita, Alema, barbecue, Tropical, SUPREMA, Louisiana, Cheeseham , EUROPA, Havaiana, Camponesa.
Your task is to produce a program this given the word puzzle and words to being found in the puzzle, determines, for each WOR D, the position of the first letter and their orientation in the puzzle.
You can assume so the left upper corner of the origin, (0,0). Furthemore, the orientation of the word is marked clockwise starting with letter A for North (Note:there be 8 possible D Irections in total).
Input
The first line of input consists of three positive numbers, the number of lines, 0 < L <=, the number of column S, 0 < C <=, and the number of words to be found, 0 < W <= 1000. The following L input lines, each one of size C characters, contain the word puzzle. Then at last the W words is input one per line.
Output
Your program should output, for each word (using the same order as the words were input) a triplet defining the coordinate s, line and column, where the first letter of the word appears, followed by a letter indicating the orientation of the WOR D according to the rules define above. Each value in the triplet must is separated by one space only.
Sample Input
20 20 10QWSPILAATIRAGRAMYKEIAGTRCLQAXLPOIJLFVBUQTQTKAZXVMRWALEMAPKCWLIEACNKAZXKPOTPIZCEOFGKLSTCBTROPICALBLBCJEWHJEEWSMLPOEKOROR Alupqwrnjoaagjkmusjaekrqeioloaoqprtvilcbzqopucajsppoutmtslpsflpouytrfgmmlkiuisxswwahcpoiytgaklmnahbvaeiakhplbgsmclogngjml Ldtikenvcswqazuaoealhoplpgejkmnutiiormncloiuftgsqacaxmopbeioqoasdhopepnbuyuyobxbioniaelojhswasmoutrkhpoiytjplnaqwdribitgl Poinuymrtemptmlmnbopafcoplhavaianalbpfsmargaritaalemabarbecuetropicalsupremalouisianacheesehameuropahavaianacamponesa
Sample Output
0 G2 C7 A4 8 C16 B4 3 E10 1 D5 7 E19 one H
"POJ-1204 Word Puzzles" (trie+ search)