Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CodeForces Div 3 - D
#include <bits/stdc++.h> using namespace std; #define int long long #define first F #define second S void solve() { int n, s; cin >> n >> s; vector<int> ans; while(n > 0) { ans.push_back(n % 10); n /= 10; } ans.push_back(0); // reverse(ans.begin(), ans.end()); int sum = 0; for(auto x: ans) { sum += x; } int c = 0; int move[ans.size()] = {0}; for(int i = 0; i < ans.size() - 1; i++) { if(sum > s) { if(ans[i] + c == 0) { move[i] = 0; c = 0; sum -= ans[i]; continue; } move[i] = 10 - (ans[i] + c); sum -= ans[i]; c = 1; } else { break; } } int res = 0; int j = 1; for(auto x : move) { cout << x << " "; res += x * j; j *= 10; } cout << "\n"; cout << res <<"\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while(t--) { solve(); } return 0; }
run
|
edit
|
history
|
help
0
march long ques 4
Matrix multiplication naive approach
basic caculate iii
BoauthCPP
Próba
fibonacci
Ballin primality test
Working variables benchmark
Merge intervals leetcode
Cpp update 1