QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752446 | #7695. Double Up | alexhamidi | WA | 0ms | 3592kb | C++14 | 1.3kb | 2024-11-16 03:27:27 | 2024-11-16 03:27:28 |
Judging History
answer
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
5 4 2 2 1 8
output:
4 4 1 8 8 1 8 8 8 16 16
result:
wrong answer 1st lines differ - expected: '16', found: '4 4 1 8 '