UVA 10132-File Fragmentation(map还原字符串)

22 篇文章 11 订阅

                                              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
题意:一些相同的文件由01构成,不小心把每份文件摔成两份,给出你摔坏后的文件组成,让你求出原文件

思路:暴力。把每个字符串与都链接一下,然后用map每个链接后的文件的数量,然后找出输入数量的一半以上的文件,则为原文件。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
const int inf=0x3f3f3f3f;
char str[1010][310];
struct node {
    char site[310];
} x[10010];
int main()
{
    int T,i,j;
    char a[20],r1[1010],r2[1010];
    int cnt,t;
    scanf("%d",&T);
    getchar();
    gets(a);
    while(T--) {
        cnt=t=0;
        while(gets(str[cnt])!=NULL) {
            if(str[cnt][0]=='\0') break;
            cnt++;
        }
        map<string,int >q;
        for(i=0; i<cnt; i++)
            for(j=i+1; j<cnt; j++) {
                strcpy(r1,str[i]);
                strcat(r1,str[j]);
                if(!q[r1])
                    strcpy(x[t++].site,r1);
                q[r1]++;
                strcpy(r2,str[j]);
                strcat(r2,str[i]);
                if(!q[r2])
                    strcpy(x[t++].site,r2);
                q[r2]++;

            }
        for(i=0; i<t; i++)
            if(q[x[i].site]>=cnt/2) {
                printf("%s\n",x[i].site);
                break;
            }
            if(T)
                printf("\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rocky0429

一块也是爱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值