原题请参考:http://poj.org/problem?id=1002
这个题目我写了好几个版本的C程序,虽然都Accepted,但普遍用时较多,还需要进一步优化。下面这个程序是其中的一个,本来是想空间换时间,结果发现用时也超过了700MS。基本思想是:开辟一个大数组,数组元素的下标对应电话号码、元素值为该号码出现的次数。每读一个号码,号码对应的元素值加1。最后依次输出元素值大于1的数组下标(即电话号码)。
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int duplicateCount = 0;
int main()
{
int i,j;
int num;
char map[25]= {'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'};
char temp;
char phoneNum[8];
int int_phoneNum;
int *count;
int duplicateFlag = 0;
count = (int *)malloc(10000000*sizeof(int));
memset(count,0,10000000*sizeof(int));
scanf("%d%c",&num,&temp);
for(i=0;i<num;i++)
{
j=0;
temp = getchar();
while(temp!='\n'&& temp!=EOF)
{
if(temp!='-')
{
if(temp>='A'&& temp<='Z')