Is it possible to somehow see what tests exactly my code does not pass? I’m pretty sure this should be correct, and have tested on my own, in which case I don’t find any wrong results.
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
string solve(string str) {
int n = str.size();
string result = str;
for(int i=(n-1)/2;i>=0;i--) {
result[n - i - 1] = result[i];
}
for(int i=0;i<n;i++) {
if (result[i] > str[i]) return result;
}
for(int i=(n-1)/2;i>=0;i--) {
if (result[i] == '9') {
result[i] = result[n - i - 1] = '0';
} else {
result[i] = result[n - i - 1] = result[i] + 1;
return result;
}
}
return "1" + string(n - 1, '0') + "1";
}
vector solve(vector &arr) {
int n =arr.size();
vector result;
for(int i=0;i<n;i++) {
result.push_back(solve(arr[i]));
}
return result;
}
int main() {
int n;
cin>>n;
vector arr(n);
for(int i=0;i<n;i++) cin>>arr[i];
vector<string> result = solve(arr);
for(int i=0;i<n;i++) cout<<result[i]<<endl;
return 0;
}
created
last reply
- 1
reply
- 30
views
- 2
users