比赛 20120330 评测结果 AAAAAAAAAA
题目名称 字符串子串 最终得分 100
用户昵称 TBK 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-03-30 22:18:48
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <string>
  7. #include <iomanip>
  8. #include <vector>
  9. #include <set>
  10. #include <algorithm>
  11. #define MAXN 0x7fffffff
  12. using namespace std;
  13. int a,b,c,d,r[10],l=0;
  14. char ch[8][1000];
  15. struct fun
  16. {
  17. char cha[1000];
  18. }f[40321];
  19. bool bo[10];
  20. int cmp ( const void *a , const void *b )
  21. {
  22. struct fun *c = (struct fun *)a;
  23. struct fun *d = (struct fun *)b;
  24. return strcmp(c->cha,d->cha);
  25. }
  26. void DFS(int k)
  27. {
  28. int i,j;
  29. if (k==a)
  30. {
  31. d=0;
  32. for (i=0;i<a;i++)
  33. for (j=0;j<strlen(ch[r[i]]);j++)
  34. {
  35. f[l].cha[d]=ch[r[i]][j];
  36. d++;
  37. }
  38. l++;
  39. }
  40. for (i=0;i<a;i++)
  41. if (bo[i]==false)
  42. {
  43. r[k]=i;
  44. bo[i]=true;
  45. DFS(k+1);
  46. bo[i]=false;
  47. }
  48. }
  49. int main(void)
  50. {
  51. freopen("substring.in","r",stdin);
  52. freopen("substring.out","w",stdout);
  53. scanf("%d",&a);
  54. for (b=0;b<a;b++) cin>>ch[b];
  55. DFS(0);
  56. qsort(f,l,sizeof(fun),cmp);
  57. cout<<f[0].cha;
  58. fclose(stdin);
  59. fclose(stdout);
  60. return 0;
  61. }
  62.