我擦啊,又被一道水题搞吐血了,原因是多case的循环条件t++被我写成t--了,我去啊,就这个错调了我一上午。。一直TLE加MLE,各种换算法又换语言,尼玛到最后发现是这么个低级错误。。真想撞墙了。。题目没什么难度,随便写都能过。。开始我用C++ map写的,其实算法是对的,后来我以为有问题又换成C了,发现C++写法虽然能过内存和时间都很大。。
#include<stdio.h>
#include<stdlib.h>
static void print(int num, int count)
{
int a = num / 10000;
int b = num % 10000;
printf("%03d-%04d %d\n", a, b, count);
}
static int cmp(const void *p1, const void *p2)
{
return *(int *) p1 - *(int *) p2;
}
int main()
{
int mp[] = { 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 0, 7, 7, 8, 8,
8, 9, 9, 9, 0 };
int N, n;
scanf("%d", &N);
char s[100];
int t, *array = malloc(100000 * sizeof(int));
for (t = 0; t < N; t++)
{
if (t)
putchar('\n');
scanf("%d", &n);
getchar();
int i, j, temp = 0;
for (i = 0; i < n; i++)
{
gets(s);
temp = 0;
for (j = 0; s[j] != '\0'; j++)
{
if (s[j] >= '0' && s[j] <= '9')
temp = temp * 10 + s[j] - '0';
else if (s[j] >= 'A' && s[j] <= 'Z')
temp = temp * 10 + mp[s[j] - 'A'];
}
array[i] = temp;
}
qsort(array, n, sizeof(int), cmp);
int prev = -1, count = 0, flag = 0;
for (i = 0; i < n; i++)
{
if (array[i] != prev)
{
if (count > 1)
{
print(prev, count);
flag = 1;
}
prev = array[i];
count = 1;
}
else
count++;
}
if (count > 1)
{
print(prev, count);
flag = 1;
}
if (!flag)
puts("No duplicates.");
}
free(array);
return 0;
}