• codeforces Round #441 C Classroom Watch【枚举/注意起点】


    C.
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    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 xwritten 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,求x满足x + x各位数和=n,有多组输出方案数和方案。

    【分析】:暴力枚举数位和。注意因为最大就是999999999=81 ,更小的数一定凑不到n, so枚举起点是max(n-81,1)

    【代码】:

    #include <bits/stdc++.h>
    using namespace std;
    int save[100];
    int putu(int n,int i)
    {
        int p=i;
        while(p)
        {
            i+=p%10;
            p/=10;
        }
        return i==n;
    }
    int main(void)
    {
        int n,ans=0;
        scanf("%d",&n);
        for(int i=max(n-81,0);i<=n;i++)
        {
            if(putu(n,i))
            {
                save[ans++]=i;
            }
        }
        printf("%d
    ",ans );
        if(ans>0)
        {
            for(int i=0;i<ans;i++)
                printf("%d
    ",save[i] );
        }
        return 0;
    }
    View Code
  • 相关阅读:
    什么是RUP
    oracle 导入导出
    jsp 标签
    java json 交互
    Spring MVC 学习过程遇到的问题
    Spring 与其他ORM 框架结合 作数据持久层解析 (转)
    Spring mvc 中快速获取request、reponse、session
    Spring 数据绑定
    spring mvc 请求对应控制器的解析策略配置
    spring 的几种注解
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7679090.html
Copyright © 2020-2023  润新知