标签:blog io os ar java for sp on 2014
题目:给定一个数N,去掉末尾的数变成M,现在已知N-M,确定N。
分析:数论,简单题。
设N = 10*a + b { 其中0 ≤ b ≤ 9 },则M = a;
N - M = N - a = 9*a + b,枚举所有的b计算出满足条件的N即可。
说明:目标500题(⊙_⊙)。
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
long long n,a;
while (cin >> n && n) {
int count = 0;
for (int b = 9 ; b >= 0 ; -- b)
if ((n-b)%9LL == 0LL) {
if (count ++) cout << " ";
cout << (n-b)/9LL*10+b+0LL;
}
cout << endl;
}
return 0;
}
标签:blog io os ar java for sp on 2014
原文地址:http://blog.csdn.net/mobius_strip/article/details/40535685