A.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
bool is_k_beautiful(int n, int k)
{
string s = std::to_string(n);
int digit_sum = 0;
for (char c : s)
{
digit_sum += c - '0';
}
return digit_sum % k == 0;
}
int find_min_beautiful(int x, int k)
{
int y = x;
while (true)
{
if (is_k_beautiful(y, k))
{
return y;
}
++y;
}
}
void solve()
{
ll x, k;
cin >> x >> k;
cout << find_min_beautiful(x, k) << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
B.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
const int N = 1e5 + 5;
ll dp[N];
void solve()
{
int n;
cin >> n;
string s;
cin >> s;
vector<int> a;
int len = s.length();
memset(dp, 0, sizeof(dp));
for (int i = 0; i < len; i++)
{
dp[i] = 0;
if (s[i] == '0')
{
a.push_back(len - i - 1);
}
}
if (s[len - 1] == '1')
{
if (!a.empty())
{
dp[1] = a.back();
a.pop_back();
}
else
{
dp[1] = -1;
}
}
else
{
dp[1] = 0;
a.pop_back();
}
for (int i = 2; i <= n; i++)
{
if (a.size() == 0)
{
dp[i] = -1;
}
else
{
dp[i] = dp[i - 1] + a.back() - i + 1;
a.pop_back();
}
}
for (int i = 1; i <= n; i++)
{
cout << dp[i] << " \n"[i == n];
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
C.样例没搞明白,以为单纯的就是最大-最小,后面再补吧,下午还有一场