QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#132479 | #6407. Classical A+B Problem | cciafrino# | WA | 1ms | 3512kb | C++14 | 1.9kb | 2023-07-30 00:12:40 | 2023-07-30 00:12:44 |
Judging History
answer
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
string sub(const string& s1, const string& s2) {
int N = int(s1.size());
string res(s1.size(), '0');
int emprestimo = 0;
int last_nn = -1;
for(int i=0; i<(int)s1.size(); i++) {
int n1 = s1[s1.size()-1 - i] - emprestimo - '0';
char aux;
if(((int) s2.size()) - i > 0) {
int n2 = s2[((int) s2.size())-1 - i] - '0';
aux = ((n1-n2 + 10) % 10) + '0';
emprestimo = (n1-n2) < 0 ? 1 : 0;
// cout << i << " . " << n1 << " " << n2 << " " << aux << " " << emprestimo << endl;
} else {
emprestimo = 0;
aux = n1 + '0';
// cout << i << " # " << n1 << " " << aux << " " << emprestimo << endl;
}
// cout << last_nn << endl;
if (aux > '0') last_nn = res.size() - i - 1;
res[res.size()-1 - i] = aux;
}
return string(res.begin() + last_nn, res.end());
}
bool check(const string& b) {
char c = b[b.size()-1];
for (int i = 0; i < int(b.size())-1; ++i) {
if (b[i] != c) return false;
}
return true;
}
int main() {
using namespace std;
cin.tie(nullptr)->sync_with_stdio(false);
int T; cin >> T;
while (T--) {
string S; cin >> S;
bool flag = true;
for(int i=S.size() && flag; i>=1; i--) {
for(char c='1'; c<='9' && flag; c++) {
string a = string(i, c);
if(S < a) continue;
string b = sub(S, a);
// cout << a << " " << b << " " << S << endl;
if(check(b)){
cout << a << " " << b << '\n';
flag = false;
}
}
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3512kb
input:
6 2 786 1332 89110 2333333 10000000000000000000000000001
output:
1 1
result:
wrong output format Unexpected end of file - token expected (test case 2)