当前位置:编程学习 > C/C++ >>

UVa 10132 - File Fragmentation

Question 2: File Fragmentation
The Problem
Your 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.
Input
The 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.
Output
For each test case, the output must 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 should 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 solutions 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 Input
1
 
011
0111
01110
111
0111
10111
Sample Output
01110111
   这题目用暴力枚举就可以,但还是错了好多次,最后检查出错在输入的地方了。 仔细读一下输入要求 相邻两个数据之间用空行隔开,最后那个数据后面是没有空行的。 而我再输入的时候写成了死循环,结果在输入最后一组数据的时候是不会处理数据的,应该写成处理到文件结束,悲催,检查了好久才检查出来
[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;  
                }  
               strcpy(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
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,