zoukankan      html  css  js  c++  java
  • NYOJ506 洗澡

     

    洗澡

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
     
    描述

    Mostrp是个爱干净的好少年。 有一次去澡堂洗澡时发现 澡堂的澡柜编号中没有出现过数字‘4’。 Mostrp 感到很好奇。可能是因为在澡堂老板眼里。数字‘4’是十分不吉利的。

    现在Mostrp知道澡柜的最大的编号N,你能帮他算出澡堂一共有多少澡柜吗?

     
    输入
    有多组数据,每行输入一个N。
    ( 1 <= N <= 50000 )
    输出
    输出澡柜的个数,输出占一行。
    样例输入
    3
    5
    样例输出
    3
    4

    起来水一题 。。。。
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    int fun(char* s)
    {
        int tot = 0;
        int len = strlen(s);
        for(int i = 0; i < len; ++i)
        {
            int cnt = s[i] - '0';
            if(s[i] > '4')
                --cnt;
            tot += cnt * (int)pow(9,len - i -1);
        }
        return tot;
    }
    
    int main()
    {
        char s[10];
        while(cin >> s)
        {
            cout << fun(s) << endl;
        }
        return 0;
    }
    
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    int fun(char* s)
    {
        int tot = 0;
        int len = strlen(s);
        for(int i = 0; i < len; ++i)
        {
            int cnt = s[i] - '0';
            if(s[i] > '4')
                --cnt;
            tot += cnt * (int)pow(9,len - i -1);
        }
        return tot;
    }
    
    int main()
    {
        char s[10];
        while(cin >> s)
        {
            cout << fun(s) << endl;
        }
        return 0;
    }
    

      

    功不成,身已退
  • 相关阅读:
    前端导出excel文件
    promise和async/await的用法
    vue element 导出 分页数据的excel表格
    mac net.core 安装问题总结
    npm报MSBUILD错误的解决办法
    现大前端开发环境配置
    git 常用命令
    NodeJs (一)
    VUE 组件通信、传值
    vue-cli 第一章
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2767986.html
Copyright © 2011-2022 走看看