CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Insomnia 2010 » Problem3

Problem3

Problem code: AX03

  • All Submissions

X Word

A crossword puzzle is a rectangular grid. It consists of grey and red square grids and two lists of descriptions. One list of descriptions is for "words" to be written across grey squares from left to right in the rows and the other list is for words to be written from top to bottom of the grey squares in the columns. One writes the words corresponding to the descriptions on the grey squares of the grid to solve a crossword puzzle. The descriptions relate to the rectangular grid according to sequential integers on grey squares which are deemed "eligible". Grey squares are deemed "eligible" if they have red squares immediately to the left or above them. Even those Grey squares are deemed "eligible" which have no squares either immediately to the left or above. No other squares are numbered. All of the squares on the first row are numbered. The numbering starts with 1 and continues consecutively from left to right of the grey squares of the first row, then from left to right of the eligible grey squares of the second row, then from left to right of the eligible grey squares of the third row and so on across all of the rest of the rows of the puzzle. The picture below illustrates a rectangular crossword puzzle grid with appropriate numbering.

On a sequence of grey squares, in a row starting on a numbered square that does not follow another grey square in the same row , an "left to right" word for a description is written. The sequence of grey squares for that word goes from left to right of the row of the numbered square, ending immediately before the next red square in the row or in the rightmost square of the row.

On a sequence of grey squares, in a column starting on a numbered square that does not follow another grey square in the same column, A 'top to bottom' word for a description is written. The sequence of grey squares for that word goes from the top to bottom of the column of the numbered square, ending immediately before the next red square in the column or in the bottom square of the column. Every grey square in a correctly solved puzzle contains a letter.

You must write a program that takes several solved crossword puzzles as input and outputs the lists of 'left to right' and 'top to bottom' words which constitute the solutions.

Input

Each input starts with a line containing two integers r and c (1< r <10 and 1< c <10), where r (the first number) is the number of rows in the puzzle and c (the second number) is the number of columns.
The r rows of input which follow each contain c characters (excluding the end-of-line) which describe the solution. Each of those c characters is an alphabetic character which is part of a word or the character "*", which indicates a red square.
The end of input is indicated by a line consisting of the single number 0.

Output

Output consists the list of 'left to right' words followed by the list of 'top to bottom' words. Words in each list must be output one-per-line in increasing order of the number of their corresponding descriptions.
The heading for the list of left to right words is "Left to right".
The heading for the list of top to bottom words is "Top to bottom".
In the case where the lists are empty (all squares in the grid are red), the Left to right and Top to bottom headings should still appear.

Example

Input:
6 7
AIM*DEN
*ME*ONE
UPON*TO
SO*ERIN
*SA*OR*
IES*DEA
0


Output:
Left to right
1.AIM
4.DEN
7.ME
8.ONE
9.UPON
11.TO
12.SO
13.ERIN
15.SA
17.OR
18.IES
19.DEA
Top to bottom
1.A
2.IMPOSE
3.MEO
4.DO
5.ENTIRE
6.NEON
9.US
10.NE
14.ROD
16.AS
18.I
20.A


Author: xpurgate
Date Added: 3-09-2010
Time Limit: 6 sec
Source Limit: 50000 Bytes
Languages: C, CPP 4.0.0-8, CPP 4.3.2, JAVA


  • Submit

Comments

  • Login or Register to post a comment.

"The picture below

srish.sriv @ 4 Sep 2010 02:46 AM

"The picture below illustrates a rectangular crossword puzzle grid with appropriate numbering."

I guess the picture is missing..

Where is the picture??

root5 @ 4 Sep 2010 11:01 PM

Where is the picture??

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com