为什么在spoj上显示sigsev错误?


## Here is the link to the question http://www.spoj.com/problems/SBANK/
## i am getting sigsev error on the spoj.i have used mergesort to sort the account number ##

#include<stdio.h>
#include<string.h>
void merge(int,int,int);
char a[10000][33];

**合并函数排序数组。由于帐号大于18位,我使用了字符串库函数来比较存储在字符串**

中的帐号。
 void mergesort(int low,int high)
{   int mid;
if(high>low)
{
     mid=(high+low)/2;
    mergesort(low,mid);
    mergesort(mid+1,high);
    merge(low,mid,high);
}
else
    return;
}
void  merge(int low,int mid,int high)
{
int i=low;
int j=mid+1;
int k=0;
char temp[10000][33];
while(i<=mid&&j<=high)
{
    if(strcmp(a[i],a[j])<0)
    {

        strcpy(temp[k],a[i]);
        i++;
    }
    else
    {
       strcpy(temp[k],a[j]);
        j++;
    }
    k++;
}
while(i<=mid)
{
    strcpy(temp[k],a[i]);
    k++;
    i++;
}
while(j<=high)
{
   strcpy(temp[k],a[j]);
    k++;
    j++;
}
k=0;
    while(low<=high)
        {
            strcpy(a[low],temp[k]);
            low++;
            k++;
        }
}

主驱动功能

在其中一家网上银行里,每天有成千上万的业务在进行。由于某些客户的业务比其他客户更活跃,一些银行账户在操作列表中出现多次。你的任务是将银行帐号按升序排序。如果一个帐户在列表中出现两次或两次以上,则在帐户编号后面写上重复次数。帐户的格式如下:2个控制数字,8位银行代码,16位识别所有者的数字(以4位数字为一组),例如(每行末尾正好有一个空格):30 10103538 2222 1233 6160 0142

银行是实时的机构,他们需要快速的解决方案。如果你觉得你可以在一个非常严格的时间限制内完成挑战,那就去吧!用一种快速的语言设计好的排序算法很可能会成功。

int main()
{
int t;
scanf("%d",&t);
while(t--)
{
    int i,n;
    int ch;
    scanf("%d",&n);
    getchar();

   for(i=0;i<n;i++)
    gets(a[i]);
  printf("n");
    mergesort(0,n-1);
    int j=1;
    for(i=0;i<n-1;i++)
    {
        if(strcmp(a[i],a[i+1])==0)
        {   j++;
           continue;
        }
        else
            {
        printf("%s %dn",a[i],j);
        j=1;
        }
    }
     printf("%s %dn",a[i],j);
}
return 0;
}
[Problem to sort bank accounts number of 26 digit][1]

如果字符串长度超过32个字符或超过10000个字符,可能会导致固定大小数组中的一个溢出。

访问未正确初始化的索引处的数据也可能导致越界读取

最新更新