Ultraviolet A 10132-File Fragmentation

Source: Internet
Author: User

Question 2: File FragmentationThe problemyur friend, a biochemistry major, tripped while carrying a tray of computer files through the lab. all of the files fell to the ground and broke. your friend picked up all the file fragments and called you to ask for help putting them back together again. fortunately, all of the files on the tray were identical, all of them broke into exactly two fragments, And all of the file fragments were found. unfortunately, the files didn't all break in the same place, and the fragments were completely mixed up by their fall to the floor. you 've translated the original binary fragments into strings of ASCII 1's and 0's, and you're planning to write a program to determine the bit pattern the files contained. inputThe input begins with a single positive integer on A line by itself indicating the number of the cases following, each of them as described below. this line is followed by a blank line, and there is also a blank line between two consecutive inputs. input will consist of a sequence of ''file fragments '', one per line, terminated by the end-of-file marker. each fragment consists of a string of ASCII 1's and 0's. outputFor each test case, the output mu St follow the description below. the outputs of two consecutive cases will be separated by a blank line. output is a single line of ASCII 1's and 0's giving the bit pattern of the original files. if there are 2N fragments in the input, it shoshould be possible to concatenate these fragments together in pairs to make N copies of the output string. if there is no unique solution, any of the possible sol Utions may be output. your friend is certain that there were no more than 144 files on the tray, and that the files were all less than 256 bytes in size. sample Input1 011011101110111011110111 Sample Output01110111 this question can use the brute force enumeration, but it is still wrong many times, finally check the error in the input place. Read the input carefully and separate the adjacent two data with empty rows. The data is not followed by empty rows. When I input the data again, it is written as an endless loop, and the result will not process the data when I input the last group of data. It should be written as processing until the end of the file, after checking for a long time, [cpp] # include <stdio. h> # include <string. h> # include <math. h> char s1 [1000] [1000]; char s2 [1000], s3 [1000]; int main () {int I, j, n, m, s, t, l1, l2, z, u, v, k, l; scanf ("% d % * c", & t); gets (s2); while (t --) {n = 0; while (gets (s1 [n]) {l = strlen (s1 [n]); if (l = 0) {break ;} n ++ ;}for (I = 0; I <= n-1; I ++) {for (j = 0; j <= n-1; j ++) {if (I = j) {continue;} st Rcpy (s2, s1 [I]); strcat (s2, s1 [j]); l1 = strlen (s2); for (z = 0, k = 0; z <= n-1; z ++) {if (z = I | z = j) {continue;} l2 = strlen (s1 [z]); if (s2 [0] = s1 [z] [0]) {for (u = 0; u <= l1-1 & u <= l2-1; u ++) {if (s1 [z] [u]! = S2 [u]) {break;} if (u = l2) {for (v = u; v <= l1-1; v ++) {s3 [v-u] = s2 [v];} s3 [v-u] = '\ 0'; for (u = 0; u <= n-1; u ++) {if (u = I | u = j | u = z) {continue;} if (strcmp (s3, s1 [u]) = 0) {break;} if (u! = N) {k = 1 ;}}if (k = 1) {k = 0; continue ;} if (s2 [l1-1] = s1 [z] [l2-1]) {for (u = l2-1, v = l1-1; u> = 0, v> = 0; u --, v --) {if (s1 [z] [u]! = S2 [v]) {break;} if (u =-1) {for (u = 0; u <= v; u ++) {s3 [u] = s2 [u];} s3 [u] = '\ 0'; for (u = 0; u <= n-1; u ++) {if (u = I | u = j | u = z) {continue;} if (strcmp (s3, s1 [u]) = 0) {break ;}} if (u! = N) {k = 1 ;}}if (k = 1) {k = 0 ;}else {break ;}} if (z = n) {break ;}} if (j! = N) {break ;}} printf ("% s \ n", s2); if (t) {printf ("\ n") ;}} return 0 ;}

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.