编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#22154 #1119. Rhodoks的2-sum问题 Compile Error 0 0 ms 0 K C++ / 1.0 K Albot 2020-02-11 21:59:38
显示原始代码
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<long long> array;
    vector<long long> l_array;
    vector<long long> r_array;
    long long n, K;
    cin >> n >> K;
    for (int i = 0; i < n; i++) {
        long long temp;
        cin >> temp;
        array.push_back(temp);
    }
    sort(array.begin(), array.end());
    if (K > *(array.end() - 1) || K < *(array.begin() + 1))
        cout << "No";
    else {
        for (int i = 0; i < n; i++) {
            if (array[i] <= K / 2)
                l_array.push_back(array[i]);
            else
                r_array.push_back(array[i]);
        }
        int flag == 0;
        for (int i = 0; i < l_array.size(); i++) {
            long long temp = l_array[i];
            for (int j = 0; j < r_array.size(); j++) {
                if (temp + r_array[j] == K) {
                    cout << "Yes" << endl;
                    flag = 1;
                    break;
                }
            }
            if (flag)
                break;
        }
    }
}

编译信息

/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:24:18: error: expected initializer before '==' token
         int flag == 0;
                  ^~
/sandbox/1/a.cpp:30:21: error: 'flag' was not declared in this scope
                     flag = 1;
                     ^~~~
/sandbox/1/a.cpp:30:21: note: suggested alternative: 'fmal'
                     flag = 1;
                     ^~~~
                     fmal
/sandbox/1/a.cpp:34:16: error: 'flag' was not declared in this scope
             if(flag) break;
                ^~~~
/sandbox/1/a.cpp:34:16: note: suggested alternative: 'fmal'
             if(flag) break;
                ^~~~
                fmal