【发布时间】:2016-11-03 12:58:58
【问题描述】:
我正在 GCC 中编译这个程序,使用 Wall 命令,它看起来很清楚。但是我的大学在线平台给出了编译时错误
9.c:在函数“compare_int”中: 9.c:8:警告:初始化从指针目标类型中丢弃限定符 9.c:9:警告:初始化会丢弃来自指针目标类型的限定符
这是代码
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000
int c=0;
int compare_int(const void *pa, const void *pb) {
const int ((*a)[1]) = pa;
const int ((*b)[1]) = pb;
if ( (*a)[0] < (*b)[0] ) return -1;
if ( (*a)[0] > (*b)[0] ) return +1;
return 0;
}
void check(int m, int lastNum, int startIndex, int v[][2], int n){
if (lastNum >= m) printf("%d\n", c);
else{
int i,max=0;
for (i=startIndex;v[i][0]<=lastNum;i++){
if (v[i][0] <= lastNum)
if (v[i][1] > max) max = v[i][1];
}
c++;
check(m, max, i,v, n);
}
}
int main(){
int m,n,i;
int line[MAX][2];
scanf("%d", &m);
scanf("%d", &n);
for (i=0;i<n;i++){
scanf("%d %d", &line[i][0], &line [i][1]);
}
qsort(line, n, sizeof line[0], compare_int);
check(m, 0, 0, line, n);
return 0;
}
该程序应该读取 2 个数字。第一个是从 0 开始的路径长度,第二个是可以填充它的对数(未排序)。然后使用贪心算法,它必须找到它需要多少段来填充它。这里的问题是用对快速排序矩阵,显然它有一些指针错误但我找不到这里有什么问题......我想它有点基本但我根本无法理解。
请帮忙!
【问题讨论】:
-
6 5 0 2 3 5 4 6 3 8 2 4 3【下1(进程12909)正常退出】
-
是的,我使用了 gdb,它运行良好。