C - 不要47
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.
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;
}
|