您的位置:首页 > 其它

cf535B. Tavas and SaDDas

2016-04-28 19:22 351 查看
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 n. 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.

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.

Examples

input
4


output
1


input
7


output
2


input
77


output
6


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10010;
int num[2][maxn];
int Count(int n){
if(n==4)return 1;
if(n==7)return 2;
int ans=2,cnt=2;
int d=10,x=0;
num[0][1]=4;num[0][2]=7;
while(1){
int temp=0;
for(int i=1;i<=cnt;++i){
num[(x+1)%2][++temp]=num[x%2][i]+4*d;ans++;
if(num[(x+1)%2][temp]==n)return ans;
}
for(int i=1;i<=cnt;++i){
num[(x+1)%2][++temp]=num[x%2][i]+7*d;ans++;
if(num[(x+1)%2][temp]==n)return ans;
}
d*=10;cnt=temp;x++;
//break;
}
}
int main()
{
int n,i,j,k,l;
scanf("%d",&n);
printf("%d\n",Count(n));
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cf535B. Tavas and Sa