广州大学第九届ACM C----不要47


C - 不要47

Time Limit:  2000/1000 MS (Java/Others)       Memory Limit:  128000/64000 KB (Java/Others) 
Problem Description

One day, XiaoMing get a mysterious(神秘的) number n.

In XiaoMing's opinion, the digits 4 and 7 is unlucky, also he hated integer 47, so if the digit of n contains 4 or 7, or n can be divided by 47, then n is unlucky, otherwise, n is lucky.

Input

The first line of the input contains an integer T(1<=T<=22) which means the number of test cases. Then T lines follow, each line consists of a single number n. The digits of n is not exceed 1,000,000.

Output

If n is lucky, you need to pirnt “Lucky!” (without the quotes(引号)) in single line, otherwise, print “Unlucky ... ...”(without the quotes(引号)) in single line.

Sample Input
3
474747
1111
1269
Sample Output
Unlucky ... ...
Lucky!
Unlucky ... ...
Hint

It was a easy problem, but it may not be solved with Java BigInteger in time. 

题目很容易理解,不要4,7和能被47整除的数,这里主要是位数的问题了,如果是简单的几位数的话相信所有人都能够轻易打出这道题的代码,但这里题目要求的是1000000位的大数字。我们所学的数字数据类型已经不能满足我们的需求了,所以我们在这里就需要用字符数组,值得注意的是,字符数组的字符需要转换成我们想要的数字值形式的话要减去一个字符 ‘0’,这道题还有一个模拟除法的操作,这个很容易理解,这里就不做解释了。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* this code is made by 1406100108
* Problem: 1354
* Verdict: Accepted
* Submission Date: 2015-04-14 15:24:03
* Time: 280 MS
* Memory: 2376 KB
*/
#include<iostream>
#include<cstring>
using namespace std;
 
 
int main()
{
     unsigned  int T;
     int i,k,len,yushu;
     unsigned lucky;
     char n[1000001];
     cin>>T;
         while (T--)
         {
             lucky=1;
             cin>>n;
             len= strlen (n);
             for (k=0;k<len;++k)
                 if (n[k]== '4' ||n[k]== '7' )      //有字符‘4’和‘7’的就认为是unlucky
                 {
                     lucky=0;
                     break ;
                 }
                 for (i=0,yushu=0;i<len;++i)          //模拟除法,主要看余数
                 {
                     yushu=yushu*10+n[i]- '0' ;
                     if (yushu>=47) yushu=yushu%47;
 
                 }
                 if (yushu==0) lucky=0;
             if (lucky) cout<< "Lucky!" <<endl;
             else cout<< "Unlucky ... ..." <<endl;            
         }      
         return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值