Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么总是runtime error

Posted by skt at 2012-07-18 15:01:21 on Problem 1002
我不知道怎么回事了,我把字符串的大小开到了1000,我把数组的大小先开到了100005,后来又开到150000,可还是runtime error……

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#define M 1000
using namespace std;
struct tele{
	int num;
	int value;
};
void trf(char &a){
	if(a=='A'||a=='B'||a=='C')	a='2';
	if(a=='D'||a=='E'||a=='F')  a='3';
	if(a=='G'||a=='H'||a=='I')  a='4';
	if(a=='J'||a=='K'||a=='L')  a='5';
	if(a=='M'||a=='N'||a=='O')  a='6';
	if(a=='P'||a=='R'||a=='S')  a='7';
	if(a=='T'||a=='U'||a=='V')  a='8';
	if(a=='W'||a=='X'||a=='Y')  a='9';
}
int cmp(tele a,tele b){
	return a.value<=b.value;
}
tele phone[100005];
tele ph[100005];
int main(){
	int test;
	char ch[M]={0};
	while(scanf("%d",&test)!=EOF){
		int i,j,k;
		int mark;
		for(i=0;i<test;i++){
			scanf("%s",ch);
			phone[i].num=0;
			phone[i].value=0;
			int len=strlen(ch);
			k=0;
			for(j=0;j<len;j++){
				trf(ch[j]);
				if(ch[j]<='9'&&ch[j]>='0'){
					phone[i].value=phone[i].value*10+ch[j]-48;
					k++;
				}	
			}
			memset(ch,'\0',sizeof(ch));
		}/*既然很耗时,那不如先排好序吧,用快排*/
		sort(phone,phone+test,cmp);
		/*将其转化为数字了,接下来要开始搜了*/
		k=0;
		for(i=0;i<test;i++){
			mark=0;
			phone[i].num=1;
			j=i+1;
			while(phone[i].value==phone[j].value){
				phone[i].num++;
				j++;
				mark=1;
				if(j==test)
					break;
			}
			if(mark!=0){
				ph[k]=phone[i];
				k++;
			}
			i=j;
			i--;
		}
		if(ph[0].num>=2){
			for(i=0;i<k;i++)
				printf("%03d-%04d %d\n",ph[i].value/10000,ph[i].value%10000,ph[i].num);
		}
		else{
			printf("No duplicates.\n");
		}
		memset(phone,0,sizeof(phone));
		memset(ph,0,sizeof(ph));
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator