gpt4 book ai didi

c - 为什么它在 spoj 上显示 sigsegv 错误..?

转载 作者:行者123 更新时间:2023-11-30 19:46:16 25 4
gpt4 key购买 nike

## 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++;
}
}

Main driving function

In one of the internet banks thousands of operations are being performed every day. Since certain customers do business more actively than others, some of the bank accounts occur many times in the list of operations. Your task is to sort the bank account numbers in ascending order. If an account appears twice or more in the list, write the number of repetitions just after the account number. The format of accounts is as follows: 2 control digits, an 8-digit code of the bank, 16 digits identifying the owner (written in groups of four digits), for example (at the end of each line there is exactly one space): 30 10103538 2222 1233 6160 0142

银行是实时机构,他们需要 FAST 解决方案。如果您觉得自己可以在非常严格的时间内应对挑战,那就来吧!使用快速语言设计良好的排序算法很可能会成功。

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 %d\n",a[i],j);
j=1;
}
}
printf("%s %d\n",a[i],j);

}
return 0;

}

[Problem to sort bank accounts number of 26 digit][1]

最佳答案

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

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

关于c - 为什么它在 spoj 上显示 sigsegv 错误..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24265597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com