C. Classroom Watch
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.
Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.
Input
The first line contains integer n (1 ≤ n ≤ 109).
Output
In the first line print one integer k — number of different values of x satisfying the condition.
In next k lines print these values in ascending order.
Examples
input
21
output
1
15
input
20
output
0
Note
In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such x.
题意:
给你一个n 找有多少个数可以由它自己加上自己的每一位=n,输出多少个,并且从小到大输出他们的数值;
解;
1e9的范围最多减去9*9个数直接暴力,查找,这次的cf b想太久,就没时间搞这个后悔
#include<iostream>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;
int solve(char *s)
{
int i = 0, j = 1,k=0,m=strlen(s);
while (i < m &&j < m &&k < m)
{
int t = s[(i + k) % m] - s[(j + k) % m];
if (!t) k++;
else
{
if (t > 0) i += k + 1;
else j += k + 1;
if (i == j) j++;
k = 0;
}
}
return min(i, j);
}
int main()
{
int n, i, j,num[111];
while (cin >> n)
{
int ans = 0;
for (i = 1; i <= 81; i++)
{
int t1 = n - i,s=0,t2=n-i;
if (t1 <= 0)
break;
while (t1)
{
s += t1 % 10;
t1 /= 10;
}
if (s + t2 == n)
num[ans++] = t2;
}
cout << ans << endl;
sort(num, num + ans);
for (i = 0; i < ans; i++)
printf("%d%c", num[i], i == ans - 1 ? '\n' : ' ');
}
return 0;
}