赞
踩
这个代码是我转的,我自己写了好几次不是这里出错就是那里出错我实在受不了了。
- /*
- ID: jinbo wu
- LANG: C++
- TASK: lgame
- */
- #include<iostream>
- #include<istream>
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #include<stack>
- #include<map>
- #include<algorithm>
- #include<queue>
- #define oo 1000000000
- #define ll long long
- #define pi (atan(2)+atan(0.5))*2
- using namespace std;
- struct node
- {
- int s[26];
- }h,p,q;
- int w[26]={2,5,4,4,1,6,5,5,1,7,6,3,5,2,3,5,7,2,1,2,4,6,6,7,5,7};
- int l,num,m,len[40000],M[40000],temp,ansnum,MaxM;
- char s[10],dict[40000][9],ans[501][10];
- void Find2(int z)
- {
- int i,j;
- for (i=z+1;i<=num;i++)
- if (M[i]<=m)
- {
- q=p;
- for (j=0;j<len[i];j++)
- if (!q.s[dict[i][j]-'a']) goto B;
- else q.s[dict[i][j]-'a']--;
- if (M[i]+M[temp]>MaxM)
- {
- MaxM=M[i]+M[temp];
- ansnum=1;
- strcpy(ans[1],dict[temp]);
- ans[1][len[temp]]=' ';
- strcpy(ans[1]+len[temp]+1,dict[i]);
- }else
- if (M[i]+M[temp]==MaxM)
- {
- ansnum++;
- strcpy(ans[ansnum],dict[temp]);
- ans[ansnum][len[temp]]=' ';
- strcpy(ans[ansnum]+len[temp]+1,dict[i]);
- }
- B: ;
- }
- }
- void getanswer()
- {
- int i,j;
- m=0;
- memset(h.s,0,sizeof(h.s));
- for (i=0;i<l;i++)
- {
- m+=w[s[i]-'a'];
- h.s[s[i]-'a']++;
- }
- ansnum=0; MaxM=0;
- for (i=1;i<=num;i++)
- if (len[i]<=l && M[i]<=m)
- {
- p=h;
- for (j=0;j<len[i];j++)
- if (!p.s[dict[i][j]-'a']) goto A;
- else p.s[dict[i][j]-'a']--;
- if (M[i]>MaxM)
- {
- MaxM=M[i];
- ansnum=1;
- strcpy(ans[1],dict[i]);
- }else
- if (M[i]==MaxM)
- strcpy(ans[++ansnum],dict[i]);
- if (l-len[i]>=3)
- {
- temp=i;
- m-=M[i];
- Find2(i);
- m+=M[i];
- }
- A: ;
- }
- return;
- }
- int main()
- {
- int i;
- freopen("lgame.dict","r",stdin);
- num=0;
- do
- {
- scanf("%s",dict[++num]);
- }while (dict[num][0]!='.');
- num--;
- for (i=1;i<=num;i++)
- {
- len[i]=strlen(dict[i]); M[i]=0;
- for (m=0;m<len[i];m++)
- M[i]+=w[dict[i][m]-'a'];
- }
- fclose(stdin);
- freopen("lgame.in","r",stdin);
- freopen("lgame.out","w",stdout);
- scanf("%s",s); l=strlen(s);
- getanswer();
- printf("%d\n",MaxM);
- for (i=1;i<=ansnum;i++) printf("%s\n",ans[i]);
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。