马走日poj java超时_poj P1002错误代码-超时

Run ID

User

Problem

Result

Memory

Time

Language

Code Length

Submit Time

10336575

Time Limit Exceeded

2368B

2012-06-21 21:52:11

#include

#include

using namespace std;

typedef struct Pnum{

char numbers[10];

int times;

struct Pnum *next;

}Phone_num;

int comp(char str1[], char str2[]){

char *sp1, *sp2;

sp1 = str1;

sp2 = str2;

while (*sp1 != '\0' && *sp1 == *sp2){

sp1++;sp2++;

}

return *sp1 - *sp2;

};

void run(char s[], Phone_num* first){

const char map[]={'2','2','2','3','3','3','4','4','4','5','5','5',

'6','6','6','7','-','7','7','8','8','8','9','9','9','-'};

char numbers[10]="";

Phone_num *ptrPnum, *tempPtr, *prePtr;

int j=0;

for (int i=0; s[i]!='\0'; ++i ){

if (s[i]=='-') continue;

if (s[i]>='A' && s[i]<='Z') {

numbers[j] = map[s[i]-'A'];

}

if (s[i]

numbers[j] = s[i];

}

j++;

}

numbers[j] == '\0';

prePtr = first;

ptrPnum = first->next;

while ((ptrPnum != NULL) && (comp(ptrPnum->numbers, numbers)) <0 ){

prePtr = ptrPnum;

ptrPnum = ptrPnum->next;

}

if (ptrPnum != NULL && !comp(ptrPnum->numbers, numbers)){

ptrPnum->times ++;

}else {

tempPtr = (Phone_num *)malloc(sizeof(Phone_num));

tempPtr-> times = 1;

memcpy(tempPtr-> numbers, numbers, 10);

tempPtr->next = ptrPnum;

prePtr->next = tempPtr;

}

//cout<

};

int main(){

int n;

char s[50];

cin>>n;

Phone_num* first, *tmp;

//malloc and init.

first = (Phone_num *)malloc(sizeof(Phone_num));

first->next = NULL;

first->times = 0;

for (int i=0; i

cin>>s;

run(s, first);

}

tmp = first->next;

int empty = 1; // No dumplication.

while ( tmp != NULL ){

if (tmp->times > 1){

empty = 0;

for (int i = 0; i < 3; i++){

cout<numbers[i];

}

cout<

for (int i = 3; i < 7; i++){

cout<numbers[i];

}

cout<times<

}

tmp = tmp->next;

}

if (empty){

cout<

}

//free the memory

while (first != NULL){

tmp = first-> next;

free(first);

first = tmp;

}

}

链表,速度不够啊~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值