codeforces96B

大家都知道,正数整数是幸运的,如果它们的十进制表示不包含4和7以外的数字。例如,数字47,744,4是幸运的,5,17,46,7不是。 幸运数字超级幸运,如果它的十进制表示包含相等数量的数字4和7.例如,数字47,7744,474477是超级幸运,4,744,467不是。 有一天,Petya遇到了一个正整数n。 帮助他找出大于等于给定的数字的最小的超级幸运数字.

Input

输入一个正整数n(n<1e9)。

Output

输出大于等于给定的数字的最小的超级幸运数字.n.

Example

Input

4500

Output

4747

Input

47

Output

47

 

这道大水题。。。做了1个小时。。。

开始没有仔细看题目要求:即4的个数和7的个数相同。然后又因为写不出dfs只好暴力模拟,其结果就是第一个样例就没过QAQ。。。后来上网搜题解,发现根本不用这么麻烦的,打个表就好了啊!!!下面附上代码(注释部分是打表的程序)

<注>这个题目有一个样例数据是99999999,比它大的是4444477777,这个数要手动写进数组。

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
const int maxn = 1e9 + 10;
typedef long long ll;
ll n;
ll a[100] = { 47,74,4477,4747,4774,7447,7474,7744,444777,447477,447747,447774,474477,474747,474774,477447,477474,477744,
744477,744747,744774,747447,747474,747744,774447,774474,774744,777444,44447777,44474777,44477477,44477747,44477774,
44744777,44747477,44747747,44747774,44774477,44774747,44774774,44777447,44777474,44777744,47444777,47447477,47447747,
47447774,47474477,47474747,47474774,47477447,47477474,47477744,47744477,47744747,47744774,47747447,47747474, 47747744,
47774447, 47774474, 47774744 ,47777444, 74444777 ,74447477, 74447747, 74447774 ,74474477 ,74474747,74474774 ,74477447,
74477474 ,74477744 ,74744477, 74744747, 74744774 ,74747447, 74747474 ,74747744 ,74774447 ,74774474 ,74774744, 74777444,
77444477, 77444747, 77444774 ,77447447 ,77447474 ,77447744, 77474447 ,77474474, 77474744 ,77477444, 77744447,77744474,
77744744,77747444,77774444 ,4444477777};

/*bool judge(ll x) {
	int t1=0;
	int t2 = 0;
	while (x)
	{
		ll tem = x % 10;
		if (tem == 4)t1++;
		else if (tem == 7)t2++;
		else return false;
		x /= 10;
	}
	if (t1 == t2)return true;
	else return false;
}*/
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	/*for (ll i = 47; i <= 8000000000; i++) {
		if (judge(i))
			cout << i << ' ';
	}*/
	cin >> n;
	for (int i = 0; i <= 99; i++) {
		if (a[i] >= n) {
			cout << a[i] << endl;
			return 0;
		}
	}
	system("pause");
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值