Click
Here to go back to the homepage.
The Owl and the Fox Solution:
#include <bits/stdc++.h>
using namespace std;
int add(int num){
int total = 0;
for(char c: to_string(num)){
total += c - '0';
}
return total;
}
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int cases;
cin >> cases;
while(cases--){
string num;
cin >> num;
int sum = 0;
for(char c: num){
sum += c - '0';
}
if(sum == 1){
cout << 0 << endl;
} else {
int ans = stoi(num) - 1;
while(add(ans) != sum -1){
ans--;
}
cout << ans << endl;
}
}
return 0;
}