C语言,尝试用堆空间作答,但编译失败。
查看原帖
C语言,尝试用堆空间作答,但编译失败。
825518
UTAsriel楼主2023/6/21 21:08

代码如下:

#include <stdio.h>
#include <stdlib.h>

int main(){
    int* pn,* arpa,* arpb;
    pn = malloc(sizeof(int));
    scanf("%d",pn);
    arpa = calloc(sizeof(int),*pn + 1);
    arpb = calloc(sizeof(int),*pn + 1);
    for(int i=1;i<=*pn;i++){
        scanf("%d",arpa+i);
    }
    for(int* x = 2;x <= *pn;x++){
        for(int* y=1;y < x;y++){
            if(*(arpa+x)>*(arpa+y)){
                *(arpb+x)++;
            }
        }
    }
    for(int* m=1;m<=*pn;m++){
        printf("%d ",*(arpb+m));
    }
    return 0;
}

(在这之前,我问过Chat GPT,但没有有意义的信息。)

2023/6/21 21:08
加载中...