| ||||||||||
| 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 | |||||||||
谁帮我看看为什么WA?计算时间优先的程序
unsigned int table[] = {
2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9
};
unsigned int HashCode(char* str)
{
unsigned int code = 0;
while (*str != 0)
{
if (*str == '-')
{
str++;
continue;
}
if (*str < 'Z' && *str >= 'A')
{
code *= 10;
code += table[*str - 'A'];
}
else if (*str >= '0' && *str <= '9')
{
code *= 10;
code += *str - '0';
}
else
{
printf("Error input\n");
}
str++;
}
return code;
}
#define MAXSIZE 10000000
int _tmain(int argc, _TCHAR* argv[])
{
unsigned short * countTable = new unsigned short[MAXSIZE];
memset(countTable, 0, sizeof(unsigned short)*MAXSIZE);
int inputSize;
bool flag = false;
char telnum[20];
FILE *f = fopen("in.txt", "r");
fscanf(f, "%d", &inputSize);
for (int i = 0; i < inputSize; ++i)
{
fscanf(f, "%s", telnum);
countTable[HashCode(telnum)]++;
if (!flag)
{
flag = true;
}
}
if (flag)
{
for (int i = 0; i < MAXSIZE; ++i)
{
if (countTable[i] > 1)
{
printf("%d-%d %d\n", i/10000, i%10000, countTable[i]);
}
}
}
else
{
printf("No duplicates.\n");
}
delete[] countTable;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator