我的做法是“加最小的数字”,然而碰到了一些诡异的事情...第一次WA了三个点,我下载了第一个数据,输入是:50074897 2,我的做法下输出应该是500487,但是答案告诉我是4897,然后我就认为0肯定是不算的,所以就有了如下的代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m, n) for(int i = m; i <= n; i++)
#define per(i, m, n) for(int i = m; i >= n; i--)
const int INF = 0x3f3f3f3f;
string str, s, s2;
void build(int start, int k) {
int n = s.length();
// cout << start << endl;
// cout << k << endl;
if (k == 0) {
rep(i, start, n - 1) {
str += s[i];
}
return ;
}
int loc, num = 10;
for (int i = start; i <= start + k; i++) {
if (s[i] - '0' < num) {
loc = i;
num = s[i] - '0';
if (num == 0) break;
}
}
str += s[loc];
build(loc + 1, k - (loc - start));
}
int main() {
ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
cin >> s2;
int n = s2.length();
rep(i, 0, n - 1) if (s2[i] != '0') {
s += s2[i];
}
// cout << s << endl;
int k, loc, num = 10;
cin >> k;
rep(i, 0, k) {
if (s[i] - '0' < num && s[i] - '0' != 0) {
loc = i;
num = s[i] - '0';
if (num == 1) break;
}
}
str += s[loc];
k -= loc;
build(loc + 1, k);
cout << str << endl;
return 0;
}
然后又WA了三个点,下载的数据却告诉我这个:68129545206 6,然后我就很愉快的输出了1226,可是答案却是12206。于是我发现:肯定是在算首位的时候才把零除去的!然后就有了如下的代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m, n) for(int i = m; i <= n; i++)
#define per(i, m, n) for(int i = m; i >= n; i--)
const int INF = 0x3f3f3f3f;
string str, s;
void build(int start, int k) {
int n = s.length();
// cout << start << endl;
// cout << k << endl;
if (k == 0) {
rep(i, start, n - 1) {
str += s[i];
}
return ;
}
int loc, num = 10;
for (int i = start; i <= start + k; i++) {
if (s[i] - '0' < num) {
loc = i;
num = s[i] - '0';
if (num == 0) break;
}
}
str += s[loc];
build(loc + 1, k - (loc - start));
}
int main() {
ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
cin >> s;
// cout << s << endl;
int k, loc, num = 10, cnt = 0;
cin >> k;
rep(i, 0, k) if (s[i] == '0') cnt++;
rep(i, 0, k + cnt) {
if (s[i] - '0' < num && s[i] - '0' != 0) {
loc = i;
num = s[i] - '0';
if (num == 1) break;
}
}
str += s[loc];
k -= loc;
build(loc + 1, k + cnt);
cout << str << endl;
return 0;
}
我自信提交,结果第六个点出现了:On column 2, read 0, expected 1. QWQ 然后第七个点还RE了QWQ