Machined Surfaces

An imaging device furnishes digital images of two machined surfaces that eventually be assembled in contact with each other. The roughness of this final contact is to be estimated. A digital image is composed of the two characters, "X" and " " (space). There are always 25 columns to an image, but the total number of rows, N, is variable. Column 1 and 25 will always have an "X". Column 1 will always belong to the left surface, and column 25 will always belong to the right surface. The left surface can extend to the right as continuous Xs.

Digital-Image View of Surfaces

XXXX      XXXXX
X      XXXXXXXX
XXXXX    XXXXXX
XX            X
XXXXXXX  XXXXXX

.     .     .
.     .     .
.     .     .
XXXXX     XXXXX

In each row of the image there can be a zero or more space characters separating the left from the right surface. There will be no more than one region of blanks in any row. For each image given, your program has to determine the total "void" that will exist after the left and right surfaces have been brought into contact. The "void" is the total count of spaces that remain. The two surfaces are brought into contact by displacing them strictly horizontally towards each other until a rightmost "X" of the left surface of some row is immediately to the left of the leftmost "X" of the right surface in that row. The original image may show the two surfaces already in contact, in which case no displacement is needed.

INPUT

The input consists of a series of digital images.
Each data set for a digital image has the following format:
a positive integer N indicating the number of rows in the image;
N lines - each line is 25 characters: one or more Xs, then zero or more spaces, followed by one or more Xs.
The end of data is indicated by the single digit 0.

OUTPUT

For each image output the value of "void", one per line

SAMPLE DATA

Input:

4
XXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX
2
XXXXXXXXX    XXXXXXXXXXXX
XXXXXXXXX  XXXXXXXXXXXXXX
3
XXXX    XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX     XXXXX
XXXXXXXXX     XXXXXXXXXXX
2
X                       X
XXXXXXX    XXXXXXXXXXXXXX
0

Output:

0
2
2
19

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 24, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

It's quiet in here...