zoukankan      html  css  js  c++  java
  • Codeforces Round #299 (Div. 2) B. Tavas and SaDDas 水题

    B. Tavas and SaDDas

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/535/problem/B

    Description

    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).
    1000000000.

    Output

    Print the index of n among all lucky numbers.

    Sample Input

    4

    Sample Output

    1

    HINT


    题意

    只由4和7组成的数字是幸运数字,然后给你个幸运数字,问你是第几个

    题解:

    1.打表
    2.随便写一下,知道个位有2个,十位有4个,百位有8个
    然后随便搞一搞就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    
    int buf[10];
    inline void write(int i) {
      int p = 0;if(i == 0) p++;
      else while(i) {buf[p++] = i % 10;i /= 10;}
      for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
      printf("
    ");
    }
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    map<int,int>s;
    int main()
    {
        string ss;
        cin>>ss;
        long long ans=0;
        long long pow=1;
        for(int i=ss.size()-1;i>=0;i--)
        {
            if(ss[i]=='4')
            {
                ans+=pow*1;    
            }
            else
            {
                ans+=pow*2;
            }
            pow*=2;
        }
        cout<<ans<<endl;
            
    }
  • 相关阅读:
    元数据Metadata
    博客园如何使用MarkDown
    zookeeper集群搭建
    Java 疑问自问自答
    R中rep函数的使用
    R中unlist函数的使用
    Windows7 系统 CMD命令行,点阵字体不能改变大小以及中文乱码的问题
    C# ConfigurationManager不存在问题解决
    Servlet中的请求转发RequestDispatcher接口的forword与Include的区别
    Servlet中的乱码问题及解决办法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4427465.html
Copyright © 2011-2022 走看看