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

Codeforces Round #299 (Div. 2)B. Tavas and SaDDas点击进入题目页面
B. Tavas and SaDDas
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

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

题意:给你一个数,输出比它小的幸运数的个数,幸运数仅由4和7组成。
题解:简单的排列组合问题。
代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
  int i,j,t,k,sum=0,arr[10],m=0;
  char a[10];
  memset(a,0,sizeof(char));
  scanf("%s",a);
  i=strlen(a);
  k=i;
  for(j=0,i--;i>=0;j++,i--)
    {arr[j]=a[i]-'0';if(arr[j]<4) m=1;}
  for(j=0;j<k;j++){
    if(m==1) printf("%d\n",0);
    else if(arr[j]>=7) sum+=j==0?2:2<<j;
    else if(arr[j]>=4) sum+=j==0?1:2<<j-1;
  }
  if(m==0) printf("%d\n",sum);
  getchar();getchar();
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值