QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#752445#7695. Double UpalexhamidiCompile Error//C++141.3kb2024-11-16 03:26:482024-11-16 03:26:49

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 03:26:49]
  • 评测
  • [2024-11-16 03:26:48]
  • 提交

answer

#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

auto cmp = [](const string& a, const string& b) {
    if (a.size() != b.size()) {
        return a.size() < b.size();
    }
    return a < b;
};



string times2(const string& s) {
    string res = "";
    int carry = 0;
    int n = s.size(); // fails 16 4 1 4 16


    for (int i = n-1; i >= 0; i--) {
        int digitVal = (s[i]-'0')*2 + carry;
        res.push_back(digitVal%10 + '0');
        carry = digitVal/10;
    }

    if (carry > 0) {
        res.push_back('1');
    }

    reverse(res.begin(), res.end());

    return res;
}


int main() {
    int n;
    cin >> n;
    vector<string> A(n);
    for (auto& a : A) cin >> a;

    while (A.size() > 1) {
        bool merged = false;

        for (int i = 0; i < A.size()-1; i++) {
            if (A[i] == A[i+1]) {
                A[i] = times2(A[i]);
                A.erase(A.begin() + i + 1);
                merged = true;
            }
        }

        if (!merged && A.size() > 1) {
            A.erase(min_element(A.begin(), A.end(), cmp)); //this is not working
        }
        for (auto& a : A) cout << a << " ";
        cout <<"\n";
    }
    cout << A[0];
    return 0;
}

详细

answer.code: In function ‘std::string times2(const std::string&)’:
answer.code:32:5: error: ‘reverse’ was not declared in this scope
   32 |     reverse(res.begin(), res.end());
      |     ^~~~~~~
answer.code: In function ‘int main()’:
answer.code:56:21: error: ‘min_element’ was not declared in this scope
   56 |             A.erase(min_element(A.begin(), A.end(), cmp)); //this is not working
      |                     ^~~~~~~~~~~