uva10132
来源:互联网 发布:linux select 实例 编辑:程序博客网 时间:2024/06/15 23:57
题目大意:
有几个相同的字符串,都被摔成了两个串,题目给出这些串,求最初始的串是什么
自己的代码WA了,别人的代码
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define N 310#define LEN 610char word[LEN];struct file{ char s[LEN]; int len;}a[N];int n,L;int cmp(struct file x ,struct file y){ return x.len < y.len;}int BF(){ int count = 0; bool used[N]; char str[LEN]; memset(used,false,sizeof(used)); for(int i=0; i<n; i++) if(!used[i]) { int ok = 0; for(int j=n-1; j>i; j--) if(!used[j] && a[i].len + a[j].len == L) { strcpy(str,a[i].s); strcat(str,a[j].s); if( !strcmp(word,str) ) { used[i] = used[j] = true; ok = 1; break; } strcpy(str,a[j].s); strcat(str,a[i].s); if( !strcmp(word,str) ) { used[i] = used[j] = true; ok = 1; break; } } if(!ok) break; count ++; } if(count == (n/2)) return 1; else return 0;}void solve(){ int i,j; int ok=0; for(i=0; a[i].len==a[0].len; i++) for(j=n-1; a[j].len==a[n-1].len; j--) { strcpy(word,a[i].s); strcat(word,a[j].s); if(BF()) { ok=1; break; } strcpy(word,a[j].s); strcat(word,a[i].s); if(BF()) { ok=1; break; } } printf("%s\n",word);}int main(){ int T; scanf("%d",&T); getchar(); getchar(); while(T--) { n = 0; while(1) { if( !gets(a[n].s) ) break; if( !strcmp(a[n].s , "") ) break; a[n].len = strlen(a[n].s); n++; } sort(a,a+n,cmp); L = a[0].len + a[n-1].len; solve(); if(T) printf("\n"); } return 0;}
0 0
- UVa10132
- uva10132
- uva10132
- 文件碎片-uva10132
- [暴力]uva10132 File Fragmentation
- uva10132-File Fragmentation
- uva10132 - File Fragmentation
- 暴力枚举--uva10132
- uva10132 - File Fragmentation(文件碎片)
- uva10132 字符串数组的qsort排序技巧
- mongodb初步
- CMake入门教程 http://blog.csdn.net/fan_hai_ping/article/details/42524205
- Google上不去的时候,可以用的一些方法
- 计算机网络的分类
- Linux下安装配置jdk7
- uva10132
- 安装MYSQL-PYTHON包遇到的问题
- 【郑轻】[1768]Lovely Circular And Linear
- C# threeView 静态添加,动态添加,全部展开,全部折叠
- Linux学习笔记1:配置Linux网络和克隆虚拟机并更改配置
- 算法设计题2.32-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- 阅读分享--计算简史
- 黑马程序员-C语言-基础语法
- C语言宏定义技巧