为什么编译没过?

难道std大法失效?蒟蒻求解
foo.cpp: In function 'int main()':
foo.cpp:13:17: error: 'sort' was not declared in this scope
sort(a[2],a[2]+n);
^

3 条评论

  • @ 2015-05-16 10:27:35

    为什么本地编译可过,求解?

    • @ 2015-05-16 12:17:04

      我来猜猜。你用了Dev-C++?

    • @ 2015-05-16 13:54:47

      正解……dev有自动开关?(⊙﹏⊙) = = !

    • @ 2015-05-16 14:07:30

      嗯。在Dec-C++里include iostream会导致许多其他库被自动包含。

  • @ 2015-05-11 17:01:02

    import java.io.*;
    import java.util.*;

    public class Main
    {

    public static void main(String[] args)
    {
    // TODO Auto-generated method stub
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int a[] = new int[n];
    for (int i = 0; i < n; i++)
    {
    input.nextInt();
    a[i] = input.nextInt();
    }
    Arrays.sort(a);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
    ans += Math.abs(a[i] - a[n / 2]);
    }
    System.out.println(ans);
    }

    }

  • @ 2015-05-09 15:55:00

    sort() 需要

    #include <algorithm>

  • 1

信息

ID
1691
难度
3
分类
其他 | 排序贪心 点击显示
标签
(无)
递交数
3915
已通过
1841
通过率
47%
被复制
15
上传者