比赛 20120330 评测结果 AAAAAAAAAA
题目名称 字符串子串 最终得分 100
用户昵称 苏轼 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-03-30 21:57:56
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. using namespace std;
  6. int n;
  7. void dfs(int x);
  8. struct hehe
  9. {
  10. char str[100];
  11. }q[100];
  12. int w[10]={0};
  13. int answer=0;
  14. char ans[1000];
  15. char ans1[1010];
  16. int la;
  17. bool used[10]={0};
  18. int main()
  19. {
  20. freopen ("substring.in","r",stdin);
  21. freopen ("substring.out","w",stdout);
  22. cin>>n;
  23. for (int i=0;i<n;i++)
  24. {
  25. cin>>q[i].str;
  26. }
  27. dfs(1);
  28. cout<<ans;
  29. return 0;
  30. }
  31.  
  32. void dfs(int x)
  33. {
  34. if (x==n+1)
  35. {
  36. if (!answer)
  37. {
  38. for (int i=1;i<=n;i++)
  39. {
  40. for (int j=0;j<strlen(q[w[i]].str);j++)
  41. {
  42. ans[la]=q[w[i]].str[j];
  43. la++;
  44. }
  45. }
  46. answer++;
  47. }
  48. else
  49. {
  50. int a=0;
  51. for (int i=1;i<=n;i++)
  52. {
  53. for (int j=0;j<strlen(q[w[i]].str);j++)
  54. {
  55. ans1[a]=q[w[i]].str[j];
  56. a++;
  57. }
  58. }
  59. if (strcmp(ans,ans1)>0)
  60. {
  61. for (int i=0;i<la;i++)
  62. {
  63. ans[i]=ans1[i];
  64. }
  65. }
  66. }
  67. }
  68. else
  69. {
  70. for (int i=0;i<n;i++)
  71. {
  72. if (!used[i])
  73. {
  74. w[x]=i;
  75. x++;
  76. used[i]=1;
  77. dfs(x);
  78. x--;
  79. used[i]=0;
  80. }
  81. }
  82. }
  83. }