| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么会Runtime Error呢?我的数组已经开的够大的了啊!由于我平时都是用cin直接输入的,
这题数据量太多,于是我就用scanf输入了,在本机上运行没什么问题,可一提交就RE。我还特意的把数组开的很大,但还是如此。实在没法了,只好求助大家了?附程序如下:
#include <stdio.h>
#include <string.h>
int Digit[26];
char Obj[16],Dic[40000][16];
int n,l,i,j,len,max;
const int Value[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};
bool Becan(char s[]);
int main()
{
scanf("%s",Obj);
n = strlen(Obj);
for (i=0; i<26; i++)
Digit[i] = 0;
for (i=0; i<n; i++)
Digit[Obj[i]-'a']++;
char str[16];
max = len = 0;
int val;
bool ok = false;
while (scanf("%s",str) && strcmp(str,"."))
{
if (ok) continue;
l = strlen(str);
if (l > n) continue;
if (Becan(str))
{
val = 0;
for (i=0; i<l; i++)
val += Value[str[i]-'a'];
if (max < val) max = val;
if (l == n)
{
ok = true; continue;
}
if (n == 6 && l == 3 || n == 7 && (l == 3 || l == 4))
strcpy(Dic[len++],str);
}
}
if (ok) goto end;
int k,h;
char temp[16];
for (i=0; i<len-1; i++)
{
strcpy(temp,Dic[i]);
for (j=i+1; j<len; j++)
{
strcat(temp,Dic[j]);
h = strlen(Dic[i]) + strlen(Dic[j]);
if (Becan(temp))
{
val = 0;
for (k=0; k<h; k++)
val += Value[temp[k]-'a'];
if (val > max) max = val;
if (h == n) goto end;
}
}
}
end: printf("%d\n",max);
return 0;
}
bool Becan(char s[])
{
int i,k,D[26];
for (i=0; i<26; i++)
D[i] = Digit[i];
k = strlen(s);
for (i=0; i<k; i++)
{
D[s[i]-'a']--;
if (D[s[i]-'a'] < 0) return false;
}
return true;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator