Winter Holiday Brush problem 4--mechanized surface?

Source: Internet
Author: User
Machined Surfaces

A imaging device furnishes digital images of two machined surfaces that eventually would be assembled in contacts with each Other. The roughness of this final contacts is estimated.

A Digital Image is composed to the two characters, "X" and "" (space). There are always columns to a image, but the number of rows,n, is variable. Column One (1) would always have an "X" in it and would be part of the left surface. The left surface can extend to the right from column one (1) as contiguous X ' s.

Similarly, column would always have an "X" in it and is the right surface. The right surface can extend to the left from column as contiguous X ' 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 is zero or more spaces characters separating the left surface to the right surface. There would never be more than a single blank region into any row.

For each image given, your are to determine the total ' void ' that would exist after the left surface has been brought into Contacts with the right surface. The ' void ' is the total count of the spaces this remains between the left and right surfaces after theyhave been brought into the contact.

The two surfaces are brought into contacts by displacing them strictly horizontally all towards each other until a rightmost "X "Of the left surface of some row are immediately to the left of the leftmost" X "of the right surface of that row. There is no rotation or twisting of this two surfaces as they are into contacts; They remain rigid, and only move horizontally.

Note:the original image may show the two surfaces already in contacts, in which case no displacement to the enters CT roughness estimation.

Input

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

A-

A single unsigned integer, N, with value greater than zero (0) and less than 13. The digit of N would be is the the the the the the the the "a line.

Next N Lines-

Each line has exactly characters; One or more X ' s, then zero or more spaces, then one or more X ' s.

The end of the data are signaled by a null data set has a zero on the the "the" of "the" of "and" further data.

Output

For each image you receive as a data set, you are are to reply with the total void (count of spaces remaining after the SURFAC Es are brought into contacts). Use the default output for a in a line.

Sample Input (character "B" for ease of reading. The actual input file would use the Ascii-space character and not "B".

4

Xxxxbbbbbbbbbbbbbbbbxxxxx

Xxxbbbbbbbbbbbbbbbxxxxxxx

Xxxxxbbbbbbbbbbbbbbbbxxxx

Xxbbbbbbbbbbbbbbbbbxxxxxx

2

Xxxxxxxxxxxxxxxxxxxxxxxxx

Xxxxxxxxxxxxxxxxxxxxxxxxx

1

Xxxxxxxxxbbbbbbbbbbbbbbxx

0

Sample Output

4

0

0

Very long English ...   With the help of Youdao dictionary slowly see ...   I do not believe that there is a way, the translation is a person said (is not), or Google use, although I still do not understand, at least easy to see more ... English learning is not very ashamed, no way to help Niang, a lot of people have brushed this problem, really Masarica Horong AH:

The point of comparison of water, there is no technical content, the key is to understand the question. A big piece of English, let a person see on the headache, the most tragic there are many words do not know ...

The general meaning of the topic is: first enter a number n, representing the next to enter a few lines of string;

Each line of string is in the form of a letter x and a space (""), with a character x on either side and a space in the middle. Each line begins with one or more x, with 0 or more spaces in the middle, with one or more x at the end.

Requirement: To move the left character X in the N line simultaneously to the right (or to the right of the character X to the left) until there is no space in the middle of a row to stop all rows moving, at which point the total number of spaces in the N row is computed.

Note: (1) The given test data xxxxbbbbbbbbbbbbbbbbxxxxx the letter ' B ' is the meaning of the space, because if you give a space, you can hardly see how many spaces in the middle, give ' B ', can see the number of spaces at a glance. There is no space in the first position of each line, that is, the X on the left has no space before it. The title gives the sentence "character" B "for ease of reading. The actual input file will uses the ascii-space character, not "B" ", meaning that the character ' B ' is for the convenience of reading, the real input files would use the white space characters in the standard ASCII code, not ' B '.

(2) The scanf function cannot be used to enter a string in a program because the scanf encounters a space, Tab, and wraps to end the read, and the string in the subject requires 0 or more strings in the middle. It is recommended that you use the Fgets function.

(3) The subject requires the end of the output with n 0, so your program has to have when n=0 exit statement. All right, very water.
Make up a story. As follows:

#include <stdio.h>

int main ()
{
	int i, j, n, zero[100] = {0}, result = 0, min;
	char temp;
	
	scanf ("%d", &n);
	for (; n!= 0;) {
		min =;
		for (j = 0; J < N; j + +) {for
			(i = 0; i < i + +)
				if (getchar () = = ')
					zero[j] + +;
			if (Zero[j] < min)
				min = zero[j];
		for (j = 0; J < N; j + +) result
			+ = zero[j]-min;
		printf ("%d\n", result);
		temp = GetChar ();
		scanf ("%d", &n);
	}
	
	return 0;
}

After submitting runtime error ... Strange, I debug the good, online check that the array is out of bounds, the array does not open large ... I change the big point submits to see, OK wrong answer ... (also collected a common OJ evaluation results table)
Too late, my mother told me to go down, tomorrow continue to engage ... By the way, look at the next question, very interesting appearance, tomorrow again ...


Keep on doing today.
#include <stdio.h>

int main ()
{
	int i, j, n, zero[100] = {0}, result, Min;
	char temp;
	
	scanf ("%d", &n);
	for (i = 0; i < n; i++) {
		temp = GetChar ();
		min =;
		result = 0;
		for (j = 0; J < N; j + +) {while
			(temp = GetChar ())!= ' \ n ')
				if (temp = =)
					Zero[j] + +;
			if (Zero[j] < min)
				min = zero[j];
		for (j = 0; J < N; j + +) result
			+ = zero[j]-min;
		printf ("%d\n", result);
		scanf ("%d", &n);
	}
	
	return 0;
}

What's wrong with wa ....    Fire big. I am ready to refer to other people's answers, hehe.    Their ideas and I am not the same, some calculated all the space and the least space and then calculate, and some line to find the number of x and then calculate, seemingly did not like me to do, really I was too weak orz ... Well, I was wrong ... I did not seriously debug, the original inside a variety of errors ... I can not bear to put the wrong code posted, miserable ...    Post it and let me have a lesson ... Finally AC good happy, paste out the code:
#include <stdio.h>

int main ()
{
	int n, J;
	char temp;

	while (scanf ("%d", &n)) {
		int zero[100] = {0}, result = 0, min = n;
		if (n = = 0) break
			;
		temp = GetChar ();
		for (j = 0; J < N; j + +) {while
			(temp = GetChar ())!= ' \ n ')
				if (temp = =)
					Zero[j] + +;
			if (Zero[j] < min)
				min = zero[j];
		for (j = 0; J < N; j + +) result
			+ = zero[j]-min;
		printf ("%d\n", result);
	}
	return 0;
}


Or use my ideas to write, this time spent more than 4 hours to engage in this problem (which contains QQ and micro-blog chat time ⊙﹏⊙ b Khan) ... To sum up: 1. Write code is too not attentive, always be QQ micro bo what interference to, speed too slow how the short code so long time. 2. No intention to debug, this problem is too serious, if in the game do not know how much time to be deducted. 3. The old likes to depend on the Niang, own aspect has not done earnestly to look for the Niang, is too ashamed ...    4. There is another, that is English to learn. Blood of the lesson ah, later to pay attention to ... OK, continue to be said to be interesting the next question ...

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.