#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int t, num, lower, sub, sum, temp, n, ans;
cin >> t;
string number;
getchar();
while(t--){
cin >> number;
num = 0;
int sz = number.size();
for(int i = 0; i < sz; i++)num = (num*10) + (number[i]-48);
sub = 9 * sz, lower = num - sub;
int flag = 0;
for(int i = lower; i < num; i++){
sum = i, temp = i;
while(temp > 0){
n = temp % 10;
sum += n;
temp /= 10;
}
if(sum == num){flag = 1, ans = i;break;}
}
if(flag)cout << ans << endl;
else cout << 0 << endl;
}
return 0;
}
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int t, num, lower, sub, sum, temp, n, ans;
cin >> t;
string number;
getchar();
while(t--){
cin >> number;
num = 0;
int sz = number.size();
for(int i = 0; i < sz; i++)num = (num*10) + (number[i]-48);
sub = 9 * sz, lower = num - sub;
int flag = 0;
for(int i = lower; i < num; i++){
sum = i, temp = i;
while(temp > 0){
n = temp % 10;
sum += n;
temp /= 10;
}
if(sum == num){flag = 1, ans = i;break;}
}
if(flag)cout << ans << endl;
else cout << 0 << endl;
}
return 0;
}
No comments:
Post a Comment