Uva414 machine surface

Source: Internet
Author: User

Machined surfaces


An imaging device furnishes digital images of two machined surfaces that eventually will 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 number of rows,N, Is variable. Column one (1) will always have
An"X"In it and will be part of the left surface. The left surface can extend to the right from column one (1) as contiguousX'S.

Similarly, column 25 will always have"X"In it and will be part of the Right surface. The right surface can extend to the left from column 25 as contiguousX'S.

Digital-Image view of Surfaces

  Left                                Right

XXXX XXXXX

XXX XXXXXXX

XXXXX XXXX

XX XXXXXX

. .

. .

. .

XXXX XXXX

XXX XXXXXX

1 25

In each row of the image, there can be zero or more space characters separating the left surface from the right surface. There will never be more than a single blankRegionIn any row.

For each image given, you are to determine the total ''void "that will exist after the left surface has been brought into contact with the right surface. the ''void "is the total count of the spaces that remains
Between the left and right surfaces after theyhave been brought into contact.

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 of that row. There is no rotation or twisting of these two surfaces as they are brought into contact; they remain rigid, and only move horizontally.

Note:The original image may show the two surfaces already in contact, in which case no displacement enters into the contact roughness estimation.

Input

The input consists of a series of digital images. Each image data set has the following format:

First line-
A single unsigned integer, N, With value greater than zero (0) and less than 13. the first digit NWill be the first character on a line.

NextNLines-
Each line has exactly 25 characters; one or more X'S, then zero or more spaces, then one or more X'S.

The end of data is signaled by a NULL data set having a zero on the first line of an image data set and no further data.

Output

For each image you receive as a data set, you are to reply with the total void (count of spaces remaining after the surfaces are brought into contact ). use the default output for a single integer on a line.

Sample input (character"B"For reading of reading. The actual input file will use the ascii-space character,
Not"B").

4XXXXBBBBBBBBBBBBBBBBXXXXXXXXBBBBBBBBBBBBBBBXXXXXXXXXXXXBBBBBBBBBBBBBBBBXXXXXXBBBBBBBBBBBBBBBBBXXXXXX2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXBBBBBBBBBBBBBBXX0

Sample output

400
 
 
 
It was another simple question, and it took me 40 minutes to get an AC...
The first problem is the problem of English. It seems that my English level is still very poor. I watched the question for half a day to understand it.
Then, a piece of code was written quickly, but wa was dead and dead, and a word was missing: character "B" for reading of reading. the actual input file will use the ascii-space character, not "B ".
Muddy coal. It wasn't B. It was a space. I wiped it...
Then, scanf cannot be used. Use the hateful gets. (I have been using C ++ for compilation, but I use C language for standard input and output. This is because C language standard I/O saves more time, and C ++ is too convenient to use, so no loss is needed)
Gets () will eat the '\ n' of the first input N and automatically record it as a row. This almost forgets...
 
Well, the question is as follows: the input figure indicates the number of spaces after the two machines are joined together.
Algorithm thinking is very simple. Calculate the number of spaces in each row from top to bottom CNT [I], and the line with the smallest number of spaces (min_blank) can be successfully joined, the CNT [I]-blank space is added after other rows are joined.
# Include <cstdio> # include <cctype> # include <cstring> using namespace STD; const int INF = 0 xffffff; char surface [15] [26]; // record image int CNT [15]; // record the number of spaces in each line int main () {int N; while (scanf ("% d", & N )! = EOF) {getchar (); // eat scanf line breaks to avoid affecting getsif (n <1 | n> 13) break; int min_blank = inf; memset (CNT, 0, sizeof (CNT); For (INT I = 0; I <n; I ++) gets (surface [I]); // In fact, it is best to use fgets (surface [I], 26, stdin), lazy for (INT I = 0; I <n; I ++) {for (Int J = 0; j <25; j ++) if (surface [I] [J] = '') CNT [I] ++; if (CNT [I] <min_blank) min_blank = CNT [I]; // minimum number of spaces} int sum = 0; For (INT I = 0; I <N; I ++) {sum + = CNT [I]-min_blank;} printf ("% d \ n", sum);} return 0 ;}

The level is still poor. How long will it take to become stronger?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.