Problem description

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

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

Examples

Input

4500
47

Output

4747
47
解题思路:题目要求输出不小于n的最小整数,这个整数要求只含有4和7这两个数字,并且4出现的次数等于7出现的次数。暴力打表(大概2分钟),水过!
打表代码:
 #include<iostream>
using namespace std;
typedef long long LL;
bool judge(LL x){
int t1 = , t2 = ;
while (x){
int a = x % ;
if (a != && a != )return false;
if (a == )t1++;
if (a == )t2++;
x /= ;
}
if (t1 == t2)return true;
else return false;
}
int main(){
for (LL i = ; i < ; ++i)
if (judge(i)){ cout << i << ','; }
return ;
}
AC代码:
 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,obj[]={,,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,};
int main(){
cin>>n;
for(int i=;;++i)
if(obj[i]>=n){cout<<obj[i]<<endl;break;}
return ;
}

再贴一种很好理解的递归写法(反正我没想到QAQ,值得学习一下)AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,ans=1LL <<;
void f(LL x,int y,int z){//通过x构造答案,y是4的个数,z是7点个数
if(x>=n && y==z)ans=min(ans,x);//答案ans满足要求:1.大于等于n 2.只存在7和4,且7的个数等于4的个数
if(x>n*)return;//答案肯定在n和n*100之间,所以x>n*100的时候退出;
f(x*+,y+,z);//当前答案x加一位数4
f(x*+,y,z+);//当前答案x加一位数7
}
int main(){
cin>>n;
f(,,);
cout<<ans<<endl;
return ;
}

C - Lucky Numbers (easy)的更多相关文章

  1. ZCMU 2177 Lucky Numbers (easy)

    传送门: http://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=2177 2177: Lucky Numbers (easy) 时间限制: 2 Sec   ...

  2. 题解 CF1428G Lucky Numbers (Easy Version and Hard Version)

    这题没有压行就成 \(\texttt{Hard Version}\) 最短代码解了( 要知道这题那么 \(sb\) 就不啃 \(D\) 和 \(E\) 了. \(\texttt{Solution}\) ...

  3. HDU 5676 ztr loves lucky numbers (模拟)

    ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...

  4. codeforces 630C Lucky Numbers

    C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...

  5. hdu 5676 ztr loves lucky numbers(dfs+离线)

    Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...

  6. codeforces 630C - Lucky Numbers 递推思路

    630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦 ...

  7. hdu 5676 ztr loves lucky numbers 打表+二分

    ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  8. hdu-5676 ztr loves lucky numbers(乱搞题)

    题目链接: ztr loves lucky numbers  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K ( ...

  9. Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers

    Roma and Lucky Numbers time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. VMware Workstation Pro 15 for Windows下载与安装

    VMware Workstation Pro 15 for Windows下载与安装 一.下载 下载地址:https://my.vmware.com/cn/web/vmware/details?dow ...

  2. 【转载】文件上传Expected MultipartHttpServletRequest: is a MultipartResolver错误解决

    引入包commons-fileupload-*.jar,版本号可以根据项目情况调整: 在spring mvc配置文件中增加配置,文件大小限制可根据项目情况调整: <!-- 上传文件拦截,设置最大 ...

  3. linux 的sed命令解释 sed ':t;N;s/\n/,/;b t' 将换行符换成逗号

    linux 的sed命令解释 sed ':t;N;s/\n/,/;b t' 将换行符换成逗号 实现的功能是吧换行符换成逗号了,自己试验过. 求解释,:t N b t 都是什么意思??? :t 定义la ...

  4. codevs 3385 拯救Oier(一) Save Oier—first

    3385 拯救Oier(一) Save Oier—first 传送门  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解       题目描述 Descr ...

  5. VsCode 格式化插件配置

    Beautify 1.在工作目录下建立.jsbeautifyrc文件: { "brace_style": "none,preserve-inline", &qu ...

  6. Eclipse中使用struts标签时出错

    原因是Action和ActionForm对应文件中没有继承相应的类,具体来说: ActionForm的编写: 必须继承org.apache.struts.action.ActionForm Actio ...

  7. 使用MySQLMigrationToolkit快速将Oracle数据导入MySQL

    使用MySQL Migration Toolkit快速将Oracle数据导入MySQL 上来先说点废话 本人最近在学习一些数据库方面的知识,之前接触过Oracle和MySQL,最近又很流行MongoD ...

  8. java中静态资源处理方法

    方案一:激活Tomcat的defaultServlet来处理静态文件 在 web.xml 中添加: <servlet-mapping> <servlet-name>defaul ...

  9. django book chapter 2

    Django’s optional GIS (Geographic Information Systems) support requires Python 2.5 to 2.7. 这里提到了djan ...

  10. eclipse上导入import git项目

    1.左上角File->import->git eclipse 可以从很多来源处import项目,项目来源可以使git/maven/general等. import来源可以看下面 2.点击g ...