B - Nearly Lucky Number
Problem description
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 47, 744, 4 are lucky and 5, 17, 467 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).
Examples
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".
解题思路:简单字符串处理。如果输入的字符串中出现'4'或'7'的次数总和num刚好为4次或7次,则输出"YES"。为什么只有4或7呢?因为规定的字符串长度最长为19,而幸运数字(只由4或7组成)有4,7,47...,第三个数47比最长长度值19还大,即num最大为19,所以只需看num是否为4或7,是则输出"YES",否则输出"NO"。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
char str[];int num=;
cin>>str;
for(int i=;str[i]!='\0';++i)
if(str[i]=='' || str[i]=='')num++;
if(num== || num==)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}
B - Nearly Lucky Number的更多相关文章
- 枚举 + 进制转换 --- hdu 4937 Lucky Number
Lucky Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- SCU3502 The Almost Lucky Number
Description A lucky number is a number whose decimal representation contains only the digits \(4\) a ...
- HDOJ 4937 Lucky Number
当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Numb ...
- 题目1380:lucky number
转载请注明文本链接 http://blog.csdn.net/yangnanhai93/article/details/40441709 题目链接地址:http://ac.jobdu.com/prob ...
- HDU 3346 Lucky Number
水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...
- 九度oj 题目1380:lucky number
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- ZOJ 3233 Lucky Number
Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- lightoj 1097 - Lucky Number(线段树)
Lucky numbers are defined by a variation of the well-known sieve of Eratosthenes. Beginning with the ...
随机推荐
- 使用DOM解析XML文档
简单介绍一下使用DOM解析XML文档,解析XML文件案例: <?xml version="1.0" encoding="UTF-8"?> -< ...
- Dynamics CRM查询实体共享给哪些人
在mscrm中,如果想查询一条记录共享给了哪些人,需要用到PrincipalObjectAccess 表,sql如下: select u.FullName,a.RC_name,sup.SystemUs ...
- dubbo之泛化引用
使用泛化调用 泛化接口调用方式主要用于客户端没有 API 接口及模型类元的情况,参数及返回值中的所有 POJO 均用 Map 表示,通常用于框架集成,比如:实现一个通用的服务测试框架,可通过 Gene ...
- hadoop job history server
默认情况下是没有启动的,需要配置完后手工启动服务. 1. 修改mapred-site.xml,添加如下内容(cluster mode, RM) <property> <nam ...
- AI 的会议总结(by南大周志华)
原文链接:http://blog.csdn.net/akipeng/article/details/6533897 这个列的更详细:http://www.cvchina.info/2010/08/31 ...
- jq 禁用复选框 和输入框
$('input').attr("readonly", ""); $('input').attr("disabled", "fal ...
- 前端工具gulp2
var gulp = require('gulp'); var less = require('gulp-less'); var htmlmin = require('gulp-htmlmin'); ...
- javaee字符缓冲输出流
package Zjshuchu; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOExcepti ...
- mysql修改原始密码
后期修改数据库用户的密码初始密码为自动生成,我们需要情况原始密码,再修改密码,mysqldmin -u root 只能用在修改为原始密码之后使用systemctl stop mysqldvim /et ...
- 查看表之间的关系 需要在eas中的商业分析-扩展报表中心-报表平台下的语义层方案管理
查看表之间的关系 需要在eas中的商业分析-扩展报表中心-报表平台下的语义层方案管理