比赛 |
20120330 |
评测结果 |
AAAAAAAAAA |
题目名称 |
字符串子串 |
最终得分 |
100 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2012-03-30 21:57:56 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- int n;
- void dfs(int x);
- struct hehe
- {
- char str[100];
- }q[100];
- int w[10]={0};
- int answer=0;
- char ans[1000];
- char ans1[1010];
- int la;
- bool used[10]={0};
- int main()
- {
- freopen ("substring.in","r",stdin);
- freopen ("substring.out","w",stdout);
- cin>>n;
- for (int i=0;i<n;i++)
- {
- cin>>q[i].str;
- }
- dfs(1);
- cout<<ans;
- return 0;
- }
-
- void dfs(int x)
- {
- if (x==n+1)
- {
- if (!answer)
- {
- for (int i=1;i<=n;i++)
- {
- for (int j=0;j<strlen(q[w[i]].str);j++)
- {
- ans[la]=q[w[i]].str[j];
- la++;
- }
- }
- answer++;
- }
- else
- {
- int a=0;
- for (int i=1;i<=n;i++)
- {
- for (int j=0;j<strlen(q[w[i]].str);j++)
- {
- ans1[a]=q[w[i]].str[j];
- a++;
- }
- }
- if (strcmp(ans,ans1)>0)
- {
- for (int i=0;i<la;i++)
- {
- ans[i]=ans1[i];
- }
- }
- }
- }
- else
- {
- for (int i=0;i<n;i++)
- {
- if (!used[i])
- {
- w[x]=i;
- x++;
- used[i]=1;
- dfs(x);
- x--;
- used[i]=0;
- }
- }
- }
- }