杭电 hdu 3346

Lucky Number:

#include<iostream>
using namespace std;
int Numsum(int m){
    int sum=0;
    while(m){
        sum+=m%10;
        m/=10;
    }
    if(sum%8==0)
        return 1;
    else
        return 0;
}
int Squaresum(int m){
    int sum=0;
    while(m){
        sum+=(m%10)*(m%10);
        m/=10;
    }
    if(sum%8==0)
        return 1;
    else
        return 0;
}
int main(){
    int n;
    cin>>n;
    while(n--){
        int m;
        cin>>m;
        if(m%8==0)
            cout<<"Lucky number!"<<endl;
        else{
            if(Numsum(m)==1)
                cout<<"Lucky number!"<<endl;
            else{
                if(Squaresum(m)==1)
                    cout<<"Lucky number!"<<endl;
                else
                    cout<<"What a pity!"<<endl;
            }
        }
    }
    return 0;
}


你可能感兴趣的:(ACM,HDU,杭电,3346)