Lucky Number

                                                                                      Lucky Number

                             题目来自杭电3346

                              题目:

                                        

Problem Description

 

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.
 


 

Input

 

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


 

Output

 

For each case, output “Lucky number!” if the number is lucky, otherwise output “What a pity!”.
 


 

Sample Input

 

2 0 8
 


 

Sample Output

 

Lucky number! Lucky number!
 


                                                 解题思路:

                                                                  把题翻译一下就是解题思路,这里要注意的几个细节,就是在代码中使用 continue 和 / 与 % 的区别,一个是做除,一个是求余

                                                总结:

                                                             也没什么好总结的,题目比较简单,看着就会

                                                源代码:

                                                        

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{

   int t, test;
   int sum1 = 0, sum2 = 0;
   scanf("%d", &t);
   while(t--)
   {
       scanf("%d", &test);
       if(test%8 == 0)
       {
          cout<<"Lucky number!"<<endl;
          continue;
       }
       while(test)
       {
           sum1 += test%10;
           sum2 += (test%10)*(test%10);
           test /= 10;
       }
       if(sum1%8 == 0 || sum2%8 == 0)
       {
           cout<<"Lucky number!"<<endl;
           continue;
       }

       cout<<"What a pity!"<<endl;
    }
    return 0;
}


这里要说明的是没有被AC 具体原因,有待分析!!!

wangxiaoming CSDN认证博客专家 架构 Spring Boot Redis
博客是很好的总结和记录工具,如果有问题,来不及回复,关注微信公众号:程序员开发者社区,获取我的联系方式,向我提问,也可以给我发送邮件,联系 1275801617@qq.com
©️2020 CSDN 皮肤主题: Age of Ai 设计师: meimeiellie 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值