Machined Surfaces

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 16M

Problem type

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 Specification

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 Specification

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

Sample Input

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

Sample Output

0
2
2
19

Comments

There are no comments at the moment.