[CodeForces - 919B] Perfect Number

版权声明: https://blog.csdn.net/qq_40829288/article/details/89346648

[CodeForces - 919B] Perfect Number

题目链接:http://codeforces.com/problemset/problem/919/B

AC代码:

#include<cstdio>

using namespace std;

//对全局变量或者对于一个或多个函数来说是全局的变量的时候,要注意上次用完该变量后变量的值,看其是否需要进行初始化。

int main() {
    int k, index = 1, stemp, s = 19;
    int arr[10005];
    int sum = 0;
    while (scanf("%d", &k) != EOF) {
        while (index <= k) {
            stemp = s;
            while (stemp != 0) {
                sum += stemp % 10;
                stemp /= 10;
            }
            if (sum == 10)
                arr[index++] = s;
            sum = 0;
            s += 9;
        }
        printf("%d\n", arr[k]);
        index = 1; //注意
        s = 19; //注意
    }
    return 0;
}
posted @ 2019-04-16 22:29 Youpeng 阅读( ...) 评论( ...) 编辑 收藏

猜你喜欢

转载自blog.csdn.net/qq_40829288/article/details/89346648
今日推荐