您的位置:首页 > 其它

Digit Generator UVa1583

2018-03-14 16:21 309 查看
#include <iostream>
using namespace std;
//求一个数的长度
int lent(int n) {
if (n < 10)	return 1;
return 1 + lent(n / 10);
}
#define MIN(n) (lent(n)) * 9
int main(void) {
int n;
while (cin >> n) {
bool isFinded = false;
for (int i = MIN(n); i < n; i++) {
int RS = i;
int temp = i;
while (temp > 0) {
RS += temp % 10;
temp /= 10;
}
if (RS == n) {
isFinded = true;
cout << i << endl;
break;
}
}
if(!isFinded)
cout << 0 << endl;
}
}

我偏不用查表法,打我啊~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: