本文主要是介绍字符串uva 10132 File Fragmentation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
uva 10132 File Fragmentation
一开始想太多,用深搜做直接超时了,换了方法过了,直接找出最长和最短,拼出得串去检查是否符合,符合输出即可
#include <stdio.h>
#include <string.h>int t;
int tt;
int min, max;
char a[300][300];
int len;
char c[300];
char cn[300];
int judge(char *c)
{int cent = 0;for (int i = 0; i < tt; i ++){if (strncmp(c, a[i], strlen(a[i])) == 0){cent ++;continue;}if (strncmp(c + len - strlen(a[i]), a[i], strlen(a[i])) == 0){cent ++;continue;}}if (cent != tt)return 1;elsereturn 0;
}
int main()
{scanf("%d", &t);getchar();getchar();int maxx;while (t --){memset(c, 0, sizeof(c));tt = 0; min = 999; max = 0;while (gets(a[tt]) != NULL && a[tt][0] != '\0'){if (strlen(a[tt]) > max){max = strlen(a[tt]);maxx = tt;}if (strlen(a[tt]) < min)min = strlen(a[tt]);tt ++;}len = max + min;for (int i = 0; i < tt; i ++){if (min == strlen(a[i])){strcpy(c, a[i]);strcpy(c + strlen(a[i]), a[maxx]);if (judge(c) == 0){printf("%s\n", c);break;}strcpy(c, a[maxx]);strcpy(c + strlen(a[maxx]), a[i]);if (judge(c) == 0){printf("%s\n", c);break;}}}if (t > 0)printf("\n");}return 0;
}
这篇关于字符串uva 10132 File Fragmentation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!