A. Nearly Lucky Number

本文介绍了一个简单的算法,用于判断一个数是否为近乎幸运数。根据定义,近乎幸运数是指其幸运数字(4和7)数量本身也是一个幸运数的整数。文章通过示例解释了如何实现这一判断,并分享了在解决问题过程中遇到的一些常见错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这道水题在涛神的帮助下顺利过关,一下是几个泪点

1,英语不过关:In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".它指的是7位数,digit位数,如果位数是幸运数字则输出,这个没考虑到

2,这个lucky number不一定全都是幸运数字,4444000.7777444都是lucky number,一定要把题目要求看仔细。

3,不管是不是lucky number 在用s统计位数的时候,num都要除以10(详见代码)

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 477444 are lucky and 517467 are not.

Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.

Input

The only line contains an integer n (1 ≤ n ≤ 1018).

Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Output

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

Sample test(s)
input
40047
output
NO
input
7747774
output
YES
input
1000000000000000000
output
NO
Note

In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".

In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".

In the third sample there are no lucky digits, so the answer is "NO".


#include<iostream>
using namespace std;

int main()
{
    long long  s;
    cin>>s;
    int c=0,i;
    while(s)
    {
    i=s%10;
    if((s%10==7)||(s%10==4))  c++;
    s=s/10;//这句别写在if 语句里面
    }
    if(c==7||c==4) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;

}


<think>嗯,用户想查找与“lucky 3322”相关的IT内容。首先,我需要理解“lucky 3322”可能指的是什么。根据提供的引用资料,关于“lucky”的关键词有几个不同的方向:幸运票(lucky tickets)、近幸运数(nearly lucky numbers)以及幸运数字(仅含4和7)。而“3322”是一个四位数的组合,可能涉及数字处理或特定算法。 首先,查看引用中的信息。引用[1]提到幸运票是前三位和后三位数字之和相等的六位数。引用[4]中Vasya认为能被3整除的票是幸运的,但用户的问是关于“3322”,这是一个四位数,可能不符合六位数的定义。但或许存在其他定义?比如,引用[4]中的问涉及将碎片拼接成能被3整除的票,可能涉及到组合数学或算法问。 接下来,“3322”本身的数字和为3+3+2+2=10,可能不符合幸运数的条件。但引用[3]中的近幸运数是数字中4和7的数量是否为幸运数。然而3322中没有4或7,所以可能不符合。引用[5]中的幸运数字仅包含4和7,所以3322也不属于。 不过,用户提到的是IT相关内容,可能涉及编程问或算法。例如,判断某个数字是否符合特定条件,或者处理数字的某种算法。比如,如何验证3322是否属于某种幸运数字的定义,或者处理类似结构的数字问。 可能的思路是,用户可能遇到类似编程目,例如判断四位数是否符合某种幸运条件,或者处理数字拆分、组合的问。例如,将3322分成两部分,如33和22,判断是否符合某种规则,如两部分之和相等,或者能被3整除等。例如,引用[4]中的问是将撕成两半的票重新组合成能被3整除的票,或许3322可以拆分成两个两位数,然后检查组合后的结果是否符合条件。 另外,用户可能误将“lucky 3322”作为一个特定的术语或目名称,需要结合现有的引用内容进行联想。例如,是否存在某个编程问,编号为3322,或者目涉及类似的概念? 总结可能的回答方向:解释“lucky”在不同编程问中的定义,分析3322是否符合这些条件,并给出相关的编程实现示例。此外,生成相关问,帮助用户进一步探索。</think>关于“lucky 3322”的IT相关内容,目前没有直接匹配的公开定义或标准算法。但基于“幸运”相关编程问的常见模式,可进行以下分析: ### 1. 数字属性验证 若将3322视为四位数,可尝试应用不同“幸运”规则验证: - **拆分验证**:将数字分为前两位(33)和后两位(22),计算和是否相等: $$33 + 22 = 55 \quad \text{不满足相等条件}$$ - **整除性验证**(引用[4]): $$3322 \div 3 = 1107.333... \quad \text{余数非零,不满足条件}$$ - **数字符统计**(引用[3][5]): - 含4或7的数量:3322中无4或7,不满足幸运数字定义 - 所有数字之和:3+3+2+2=10,非4或7的倍数 ### 2. 可能的编程问场景 若需设计类似“幸运3322”的算法,可参考以下模板: ```python def is_lucky_3322(num): digits = list(map(int, str(num))) # 示例规则:前两位之和等于后两位之和 return sum(digits[:2]) == sum(digits[2:]) print(is_lucky_3322(3322)) # 输出:3+3 vs 2+2 → False ``` ### 3. 相关数据结构应用 处理数字验证问时常用技术: - **字符串转换**:`str(3322) → "3322"` - **数位拆分**:`[int(d) for d in str(num)]` - **滑动窗口**:适用于长数字的连续子串检测
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值