UVA 10132 File Fragmentation(字符串还原)
来源:互联网 发布:手机录制视频剪辑软件 编辑:程序博客网 时间:2024/06/05 19:07
Description
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
有一些相同的文件都被摔成了两半,要求把原文件输出。。
数据不大,将所有的可能放在map中,最后查询一下就可以了。
这输出输出太坑人了,输出的示例之间要有换行,然后样例之间的输入结束是换行,最后一个已EOF结束。。
#include <iostream>#include <cstdio>#include <cstring>#include <stdlib.h>#include <algorithm>#include <cmath>#include <map>#define MAX 0x3f3f3f3f#define N 1010using namespace std;int a[N];struct node{ char x[300];} q[N*10]; //保存所有文件可能的组合方式char s[N][300];int main(){ int T; char t[10]; scanf("%d%*c",&T); gets(t); while(T--) { int s1=0; while(gets(s[s1])!=NULL) { if(s[s1][0]=='\0') break; s1++; } map<string,int>v; int cnt=0; for(int i=0; i<s1; i++) { for(int j=i+1; j<s1; j++) { char a1[600],a2[600]; if(strcmp(s[i],s[j])==0) //两半文件相同,只计算一次 { strcpy(a1,s[i]); strcat(a1,s[j]); if(!v[a1]) { strcpy(q[cnt++].x,a1); } v[a1]++; } else { strcpy(a1,s[i]); strcat(a1,s[j]); if(!v[a1]) { strcpy(q[cnt++].x,a1); } v[a1]++; strcpy(a2,s[j]); strcat(a2,s[i]); if(!v[a2]) { strcpy(q[cnt++].x,a2); } v[a2]++; } } } for(int i=0; i<cnt; i++) { if(v[q[i].x]>=s1/2) //不能是 '=' 因为所有摔坏的文件完全相同时, { //map里的值是大于s1/2的 printf("%s\n",q[i].x); break; } } if(T) printf("\n"); } return 0;}
- UVA 10132 File Fragmentation(字符串还原)
- UVA 10132-File Fragmentation(map还原字符串)
- 字符串uva 10132 File Fragmentation
- UVa Problem 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
- luajit2.1 iOS编译64bit以及通用库
- 51单片机学期总结
- OBJECTPROPERTY用法整理
- css、js的相互阻塞
- ViewPager onPageChangeListener总结
- UVA 10132 File Fragmentation(字符串还原)
- Android App整体架构设计的思考(二)
- 在中文联想输入的情况下使textview控制输入的字数
- 开源项目源码解析-CircularFloatingActionMenu 源码解析
- Valid Sudoku - Leetcode
- 工欲善其事必先利其器之Linux Man 命令快捷键
- 开源项目源码解析-PhotoView 源码解析
- 适配器模式(Adapter Pattern)
- ionic项目之ngcordova插件之camera