题解 | #最高分与最低分之差#

最高分与最低分之差

http://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2

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

int Sort(const void* a, const void* b)
{
    return *(int*)a-*(int*)b;
}
int main()
{
    int n = 0, m = 0;
    int* p = NULL;
    scanf("%d", &n);
    p = (int*)malloc(sizeof(int) * n);
    if(p==NULL)
        return 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &m);
        *(p + i) = m;
    }
    qsort(p, n, sizeof(int), Sort);
    printf("%d\n", *(p + n - 1) - *(p));
    free(p);
    p=NULL;
    return 0;
}
全部评论

相关推荐

一表renzha:不是你说是南通我都没往那方面想,人家真是想表达那个意思吗?
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务