uva10132-File Fragmentation

File Fragmentation

The Problem

Your friend, a biochemistry major, tripped while carrying a tray of computerfiles 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 forhelp putting them back together again.

Fortunately, all of the files on the tray were identical, all of them brokeinto 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 ASCII1's and 0's, and you're planning to write a program to determine thebit 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 patternof the original files.If there are 2N fragments in the input, it should be possible to concatenatethese 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
题意:多份相同的文件碎成两半,碎的地方不相同,现在要还原这文件.
思路:因为文件碎的地方不相同,所以只需要两份文件(四个碎片两两组和相同的话)就能将文件还原.如果只有两个碎片,那么有两种还原方式,随便输出一种即可.
先将文件按长度从小到大排序,只需将第一第二个碎片与倒数第一第二个碎片组合...
其实代码看了别人的,然后自己就想不出来了,不是自己做的心里不太安额可怜
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int cmp(string A,string B)
{
    return A.size()<B.size();
}
int main()
{
    int T,len,l,i,j;
    string s[300],str1,str2,str3,str4;
    cin>>T;
    getchar();
    getchar();
    while(T--)
    {
        l=0;
        while(getline(cin,s[l])&&!s[l].empty())
        {
            l++;
        }
        sort(s,s+l,cmp);
        if(l<=2)
            cout<<s[0]+s[l-1]<<endl;
        str1=s[0]+s[l-1];
        str2=s[l-1]+s[0];
        str3=s[1]+s[l-2];
        str4=s[l-2]+s[1];
        if(str1==str3||str1==str4)
        {
            cout<<str1<<endl;
        }
        else if(str2==str3||str2==str4)
        {
            cout<<str2<<endl;
        }
        else
        {
            str1=s[0]+s[l-2];
            str2=s[l-2]+s[0];
            str3=s[1]+s[l-1];
            str4=s[l-1]+s[1];
            if(str1==str3||str1==str4)
            {
                cout<<str1<<endl;
            }
            else if(str2==str3||str2==str4)
            {
                cout<<str2<<endl;
            }
        }
        if(T)
            cout<<endl;
    }


}









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值