A. Classroom Watch
来源:互联网 发布:各国域名后缀 编辑:程序博客网 时间:2024/05/16 15:14
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.
The first line contains integer n (1 ≤ n ≤ 109).
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.
21
115
20
0
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.
解题说明:此题是一道模拟题,用X加上X每一位的每一位得到这个数,逆推所有的x
#include<cstdio>#include<iostream>#include<string>#include<cstring>#include<cmath>using namespace std;int main(){long n;long i, t, sum;int flag = 0;int a[100];scanf("%ld", &n);for (i = n - 100; i<n; ++i){sum = i;t = i;while (t>0){sum += t % 10;t /= 10;}if (sum == n){flag++;a[flag] = i;}}printf("%d\n", flag);for (i = 1; i <= flag; i++){printf("%ld\n", a[i]);}return 0;}
- A. Classroom Watch
- Codeforces 875A Classroom Watch
- CodeForces 875A Classroom Watch
- Codeforces 875A Classroom Watch 题解
- (Coderforces 875A)A. Classroom Watch 暴力 + 思维
- codeforces——875A —— Classroom Watch
- codeforces875A Classroom Watch
- Codeforces875A-Classroom Watch
- Codeforces 876C Classroom Watch
- Codeforces 876 C Classroom Watch
- CF C. Classroom Watch【枚举】
- CodeForces 876C Classroom Watch
- codeforces 876C Classroom Watch
- CodeForces-876C Classroom Watch
- Codeforces Round #441 div2 C. Classroom Watch
- Codeforces Round #441 C. Classroom Watch
- C. Classroom Watch(思路)---codeforces
- Classroom Watch (Codeforces Round #441 (Div.2) )
- 云存储平台——Seafile搭建
- Centos7下docker安装log.io日志监控
- 进程
- PEP8 Python 编码规范整理
- 基本
- A. Classroom Watch
- 个人知乎 ##基础六/功能六-异步队列实现赞踩站内信
- Item 10:令赋值操作符返回一个this指针【effective C++读书笔记】
- 机器学习中学习曲线的 bias vs variance 以及 数据量m
- 7.1
- 链路层
- Java小面试题(2)
- ARM中MMU原理剖析
- 数据结构<十二>: 不可变的String实现