| ||||||||||
| 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 | |||||||||
Run time error , 高手看下是怎么回事啊 #include <iostream>
#include <cstdlib>
using namespace std;
#define ROW 100000
char format(const char &s);
char *RegularTel[ROW];
int OccurTimes = 1;
int compare(const void *a, const void *b);
int main()
{
long int testnum;
cin >> testnum; //cin 过后有回车,所以应该用getchar()将回车接收
getchar();
for (int i=0; i< testnum; i++)
{
RegularTel[i]=new char [8];
}
for (int i=0; i < testnum; i++)
{
char ch;
int j=0;
while(true)
{
scanf("%c", &ch);
if (ch == '\n')
break;
if (ch == '-')
continue;
RegularTel[i][j] = ch;
j++;
}
RegularTel[i][j] = '\0';
}
int j;
char tmp;
int count = 0 ;
for (int i=0; i < testnum; i++)
{
count=0;
j=0;
tmp = RegularTel[i][j] ;
while( tmp != '\0' )
{
if (tmp >= '0' && tmp <= '9')
{
RegularTel[i][count] = tmp;
}
else
{
RegularTel[i][count] = format(tmp);
}
j++;
count = (count +1)%7;
tmp = RegularTel[i][j];
}
}
qsort(RegularTel, testnum, 4, compare);
int tmp2;
int flag=0;
for (int i=0; i < testnum; i++)
{
tmp = i;
if ((i+1) < testnum)
{
while (strcmp(RegularTel[i],RegularTel[i+1]) == 0 )
{
OccurTimes++;
i++;
if ( i >=testnum )
break;
}
}
if (OccurTimes >=2)
{
for (int ii=0; ii < 3; ii++)
cout << RegularTel[tmp][ii];
cout << '-';
for (int jj=3; jj < 7; jj++)
cout << RegularTel[tmp][jj];
cout << " " << OccurTimes <<endl;
flag=1;
}
OccurTimes = 1;
}
if (flag ==0)
{
cout << "No duplicates." <<endl;
}
for (int i=0; i< testnum; i++)
{
delete [] RegularTel[i];
}
return 0;
}
char format(const char &s)
{
char tmp;
switch(s)
{
case 'A':
case 'B':
case 'C':tmp = '2';break;
case 'D':
case 'E':
case 'F':tmp='3';break;
case 'G':
case 'H':
case 'I':tmp='4';break;
case 'J':
case 'K':
case 'L':tmp='5';break;
case 'M':
case 'N':
case 'O':tmp='6';break;
case 'P':
case 'R':
case 'S':tmp='7';break;
case 'T':
case 'U':
case 'V':tmp='8';break;
case 'W':
case 'X':
case 'Y':tmp='9';break;
}
return tmp;
}
int compare(const void *a, const void *b)
{
return strcmp(*(char **)a,*(char **)b);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator