编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#22241 #1119. Rhodoks的2-sum问题 Compile Error 0 0 ms 0 K C++ / 589 B 电类937权冬瑞 2020-02-12 9:09:26
显示原始代码
#include <stdio.h>
#include <vector>
int main() {
    long int n, k;
    scanf("%ld,%ld", &n, &k);
    std::vector<long int> a;
    std::vector<long int>::iterator p = a.begin(n);
    if (n == 1) {
        printf("Yes");
        for (long int i = 0; i < n; i++) {
            scanf("%ld", (p + i));
        }
    } else {
        for (long int i = 0; i < n - 1; i++) {
            for (long int j = i + 1; j < n; j++) {
                if (*(p + i) + *(p + j) == k) {
                    printf("Yes");
                } else {
                    printf("No");
                }
            }
        }
    }
    return 0;
}

编译信息

/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:7:48: error: no matching function for call to 'std::vector<long int>::begin(long int&)'
     std::vector<long int>::iterator p=a.begin(n);
                                                ^
In file included from /usr/include/c++/8/vector:64,
                 from /sandbox/1/a.cpp:2:
/usr/include/c++/8/bits/stl_vector.h:698:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::begin() [with _Tp = long int; _Alloc = std::allocator<long int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<long int*, std::vector<long int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = long int*]'
       begin() _GLIBCXX_NOEXCEPT
       ^~~~~
/usr/include/c++/8/bits/stl_vector.h:698:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/8/bits/stl_vector.h:707:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_iterator std::vector<_Tp, _Alloc>::begin() const [with _Tp = long int; _Alloc = std::allocator<long int>; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const long int*, std::vector<long int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const long int*]'
       begin() const _GLIBCXX_NOEXCEPT
       ^~~~~
/usr/include/c++/8/bits/stl_vector.h:707:7: note:   candidate expects 0 arguments, 1 provided
/sandbox/1/a.cpp:11:15: warning: format '%ld' expects argument of type 'long int*', but argument 2 has type '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' [-Wformat=]
         scanf("%ld",(p+i));
               ^~~~~ ~~~~~
/sandbox/1/a.cpp:5:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%ld,%ld",&n ,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~
/sandbox/1/a.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%ld",(p+i));
         ~~~~~^~~~~~~~~~~~~