首页 > ACM题库 > HDU-杭电 > HDU 3346-Lucky Number[解题报告]HOJ
2014
03-16

HDU 3346-Lucky Number[解题报告]HOJ

Lucky Number

问题描述 :

To Chinese people, 8 is a lucky number. Now your task is to judge if a number is lucky.
We say a number is lucky if it’s a multiple of 8, or the sum of digits that make up the number is a multiple of 8, or the sum of every digit’s square is a multiple of 8.

输入:

The first line contains an integer stands for the number of test cases.
Each test case contains an integer n (n >= 0).

输出:

The first line contains an integer stands for the number of test cases.
Each test case contains an integer n (n >= 0).

样例输入:

2
0
8

样例输出:

Lucky number!
Lucky number!

#include<cstdio>
int main(){
    int t,n,s1,s2;
    scanf("%d",&t);
    while(t--){
        scanf("%D",&n);
        if(n%8==0){
            printf("Lucky number!\n");
            continue;
        }
        for(s1=s2=0;n;){
            s1+=n%10;
            s2+=(n%10)*(n%10);
            n/=10;
        }
        if(s1%8==0||s2%8==0){
            printf("Lucky number!\n");
            continue;
        }
        printf("What a pity!\n");
    }
}

参考:http://blog.csdn.net/gubojun123/article/details/9075479


  1. 第二种想法,我想来好久,为啥需要一个newhead,发现是把最后一个节点一直返回到嘴上面这层函数。厉害,这道题之前没样子想过。

  2. 算法是程序的灵魂,算法分简单和复杂,如果不搞大数据类,程序员了解一下简单点的算法也是可以的,但是会算法的一定要会编程才行,程序员不一定要会算法,利于自己项目需要的可以简单了解。