Codeforces Round #299 (Div. 2)B. Tavas and SaDDas

B. Tavas and SaDDas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

The problem is:

You are given a lucky number nLucky 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.

If we sort all lucky numbers in increasing order, what's the 1-based index of n?

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

Input

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Output

Print the index of n among all lucky numbers.

Sample test(s)
input
4
output
1
input
7
output
2
input
77
output
6


这道题就是给你个n,求出在1到n有多少个只有4和7组成的数

就是用队列做一下就ok了
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
#define ll long long
int main()
{
    ll i,j;
    ll  n;
    ll  cnt;
     cin>>n;
        cnt=0;
        ll  x,y;
        ll  a;
        queue<ll> que;
        que.push(4);
        que.push(7);
        while(1)
        {
            x=que.front();
            que.pop();
            if(x<=n)
            {
                cnt++;
            }
            else break;
            a=x*10+4;
            que.push(a);
            a=x*10+7;
            que.push(a);
            y=que.front();
            que.pop();
            if(y<=n)
                cnt++;
            else break;
            a=y*10+4;
              que.push(a);
            a=y*10+7;
              que.push(a);
        }
  cout<<cnt<<endl;


}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值