uva 10132 - File Fragmentation
来源:互联网 发布:淘宝联盟不提现会怎样 编辑:程序博客网 时间:2024/06/05 17:42
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
1011011101110111011110111
Sample Output
01110111
题意:很多相同的二进制的字符串被破坏为不同的两部分,根据破坏的查找出原来的字符串顺序
先进行排序找出最长的和最短的,确定出字符串原长度,最长的和最短的两种组合其中一种是原字符串的顺序;
再根据第二个字符串与其他字符串的长度和为原字符串长度的进行比较,确定两种组合中的一种
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;string s[1000];string a,b;int length,n;char ss[1000];bool cmp(string a,string b){ return a.size()<b.size();}bool judge(){ for(int i=n-1; i>=0; --i) { if((s[i].size()+s[1].size())!=length) continue; b=s[1]+s[i]; if(b==a) return true; b=s[i]+s[1]; if(b==a) return true; } return false;}int main(){ int t; int MIN,MAX; scanf("%d\n",&t); while(t--) { n = 0; while (gets(ss)&&ss[0]) { s[n]=ss; n++; } sort(s,s+n,cmp);// for(int i=0; i<n; i++)// cout<<s[i]<<endl; MIN=s[0].size(); MAX=s[n-1].size(); length=MIN+MAX; for(int i=n-1; i>=0&&s[i].size()==MAX; --i) { a=s[0]+s[i]; if(judge()) break; a=s[i]+s[0]; if(judge()) break; } cout<<a<<endl; if(t) cout<<endl; } return 0;}
- UVa 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- uva 10132 - File Fragmentation
- uva 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- UVA 10132 File Fragmentation
- UVa:10132 File Fragmentation
- UVA 10132 - File Fragmentation
- uva 10132 File Fragmentation
- uva 10132 File Fragmentation
- uva 10132 File Fragmentation
- uva 10132 - File Fragmentation
- uva 10132 - File Fragmentation
- UVA - 10132 File Fragmentation
- uva 10132 File Fragmentation
- UVA 10132 File Fragmentation
- 某年的第几天2
- 程序员的奋斗史(四十五)——大学断代史(九)——独自南下的岁月
- 學習新道路,動手做就對了:黃敬群 at TEDxNTHU 2014
- Google Protocol Buffer学习笔记
- ios扩展的一些知识点
- uva 10132 - File Fragmentation
- 将空调已经天雨花台
- jquery checkbox 再次勾选出问题 attr() prop()
- C语言基础知识之命令行参数
- 数据挖掘经典算法之朴素贝叶斯分类器
- 疯狂文件年付维护
- 让Android控件随着屏幕旋转自由转移至任何地方(附demo)
- 更合适的合适的风格史蒂夫
- 的风格vewfgewqfgqe