UVa 10132 - File Fragmentation
Question 2: File FragmentationThe 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++ ,
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊